#include <iostream>
using namespace std;
/*
命令行
vimtutor vim参考文档
vim .vimrc
:set number vim以后编辑时候自动带行数
vim
Esc
0 跳到行首
$ 跳到行尾
shift v 选择一整行 jk上下移动 =自动对齐
J 把下一行移动到当前行
: vs 自动分屏, ctrl ww 跳转屏幕 :wq退出一个分屏
:set hlsearch 选中的词高亮显示
:set showmatch //选中左括号时右括号也跟着亮
:set tabstop=4 一个tab键空4格
编辑状态下:
Ctrl p 或者 Ctrl n 自动补全
scp 源用户名@ip地址:文件目录 目的路径
scp kyp@192.168.37.130:/home/kyp/a.cpp ./
类比于 cp 源文件 目的文件
*/
/*
关键字 alignas
alignas(0 1 2 4 8 16 ...) //2的次方倍
struct alignas(8) S{}; //设置对齐方式,8字节对齐
alignof() //字节对齐数,类比于sizeof()
struct alignas(1) mydouble{double d;}; //还是8字节对齐
struct alignas(0) CC{}; //无效
and &&
and_eq &=
asm //内嵌汇编
compl ~
dynamic_cast 失败指针返回NULL,失败引用抛出异常(没有空引用)
*/
struct alignas(8) S {}; //8字节对齐
//alignof() 字节对齐数类比sizeof()
void test1() {
int a = 1;
int b = 2;
int* c = new int(3);
int* d = new int(4);
static int e = 5;
cout << "pa = " << int(&a) << endl;
cout << "pb = " << int(&b) << endl;
cout << "pc = " << int(c) << endl;
cout << "pd = " << int(d) << endl;
cout << "pe = " << int(&e) << endl;
}
class A {
private:
int i;
void Afunc1() {
cout << "A::i = " << i << endl;
}
public:
A(int d = 2) :i(d) {}
int Afunc2() {
return i;
}
void Afunc3() {
Afunc1();
};
};
class B : public A {
public:
void Bfunc1() {
cout << Afunc2() << endl;
}
void Bfunc2() {
Afunc3();
}
};
void test2() {
B b;
b.Bfunc1();
b.Bfunc2();
}
class C {
private:
int c;
void Cfunc1() {
cout << "C::c = " << c << endl;
}
public:
C(int d = 2) :c(d) {}
};
class D : public C{
public:
void Dfunc1() {
int* p = reinterpret_cast<int*>(this); //强转,重新解释
cout << *p << endl;
}
void Dfunc2() {
void(*pfunc)() = NULL; //函数型指针
_asm {
mov eax, C::Cfunc1;
mov pfunc, eax;
}
pfunc();
}
};
void test3() {
D d;
d.Dfunc1();
d.Dfunc2();
}
int main()
{
//test1();
//test2();
test3();
system("pause");
return 0;
}