虚函数表指针 的位置
来源:互联网 发布:windows官方下载地址 编辑:程序博客网 时间:2024/06/17 16:05
/* 虚函数表指针的位置: 判断当前编译器把虚函数表指针放在类的内存结构的最前面还是最后面*/#include <iostream>using namespace std;class CObj{public: CObj(void){} virtual void Foo(void){} int m_nID;};int main(int argc, char* argv[]){ CObj obj; char *pObj = reinterpret_cast<char*>(&obj); char *pMember = reinterpret_cast<char*>(&obj.m_nID); if(pObj == pMember) { cout<<"The vPointr is in the end of class"<<endl; } else { cout<<"The vPointr is in the head of class"<<endl; } system("pause"); return 0;}