日志20191203(3)

#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;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值