虚函数表指针 的位置

/* 虚函数表指针的位置: 判断当前编译器把虚函数表指针放在类的内存结构的最前面还是最后面
*/

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

你可能感兴趣的:(虚函数表指针的位置)