CChild child; CChild* pChild = &child; const char* pname1 = typeid(child).name(); const char* pname2 = typeid(pChild).name(); pname1 : "class CChild" pname2 : "class CChild*" 【干净的class,内存布局】 COffsetTest oftest; COffsetTest* pclass = &oftest; int* px = &oftest.x; int* py = &oftest.y; pclass = 0x0012f45c px = 0x0012f45c py = 0x0012f460 【有虚函数表且多继承的class,内存布局】 CChild child; CChild* pChild = &child; CParent* pParent1 = (CParent*)pChild; CParent2* pParent2 = (CParent2*)pChild; int *pChildX = &child.x; int *pParentX1 = &pParent1->param1; int *pParentX2 = &pParent2->param2; pChild = 0x0012f5a0 pParent1 = 0x0012f5a0 pParent2 = 0x0012f5a8 pChildX = 0x0012f5b4 pParentX1 = 0x0012f5a4 pParentX2 = 0x0012f5ac 内存布局 [基类1虚函数表指针] [基类1成员变量] [基类2虚函数表指针] [基类2成员变量] [自身类虚函数表指针(如果有)] [自身类成员变量] 【rtti信息】 存储在虚函数表的第一个位置 - pParent1 0x0012f5a0 {_fun1=0x0041173a CChild::callfunc(int) x=-858993460 } CParent * + [CChild] {_fun1=0x0041173a CChild::callfunc(int) x=-858993460 } CChild - __vfptr 0x004259dc const CChild::`vftable'{for `CParent'} * [0] 0x004111ef CChild::`vector deleting destructor'(unsigned int) * [1] 0x00411d89 CParent::parent1(void) *