struct和class都可以用来创建类
区别在于:
- class默认成员权限是private
- struct默认成员权限是public
c++编程规范
- 变量名参考规范
全局变量:g_
局部变量:m_
静态变量:s_
使用驼峰标记(mAge)

bew出来的被分配在堆中,需要手动清空内存。
内存布局
class Person{
pubic:
int m_id;
int m_age;
int m_hegiht;
//连续按照定义顺序排列
}

类是如何调用函数并且知道调用该函数的是哪个类
假如有person1和person2两个类,编译器如何知道调用类中的函数时,是person1调用的还是person2调用的?
c++中定义了this指针。

ecx存储的是 person1的地址值。然后调用成员函数。

[ebp-8]是this指针的地址,将person1的地址值存放在this指针中。
然后将this指针的值存放在eax寄存器中,将3写入eax寄存器。
完整汇编段:


this可以省略
用指针和对象直接访问的区别



开辟栈空间,为了清理之前的垃圾数据,会全部填充0xcch,也就是汇编指令int3(断点)。
网友评论