构造函数中能调用虚函数,也能确定虚表指针的存在。
能否通过下面的结果确定虚表指针在构造函数调用前就初始化好了?欢迎赐教
class A { typedef void(*fp)(); public: virtual void foo() { cout << "virtual void foo()" << endl; } virtual void bar() { cout << "virtual void bar()" << endl; } A() { cout << "A()" << endl; int* p = (int*)*(int*)(this); cout << p << endl; fp f = (fp)(*p); f(); f = (fp)(*(p + 1)); f(); } }; void test() { A a1, a2; int* p = (int*)*(int*)(&a1); cout << p << endl; p = (int*)*(int*)(&a2); cout << p << endl; }