c++源码如下:
#include <cstdio> #include <iostream> using namespace std; class Top { public: int i; }; class Left : virtual public Top { public: int j; }; class Right : virtual public Top { public: int k; }; class Bottom : public Left, public Right { public: int l; }; int main() { Bottom b; int Top::*tip = &Top::i; int Bottom::*bip = &Bottom::i; int Left::*lip = &Left::i; int Right::*rip = &Right::i; int Left::*ljp = &Left::j; int Bottom::*bjp = &Bottom::j; int Right::*rkp = &Right::k; int Bottom::*bkp = &Bottom::k; int Bottom::*blp = &Bottom::l; cout << "sizeof(tip) = " << sizeof(tip) << endl; cout << "sizeof(bip) = " << sizeof(bip) << endl; cout << "sizeof(lip) = " << sizeof(lip) << endl; cout << "sizeof(rip) = " << sizeof(rip) << endl; cout << "sizeof(ljp) = " << sizeof(ljp) << endl; cout << "sizeof(bjp) = " << sizeof(bjp) << endl; cout << "sizeof(rkp) = " << sizeof(rkp) << endl; cout << "sizeof(bkp) = " << sizeof(bkp) << endl; cout << "sizeof(blp) = " << sizeof(blp) << endl; }
运行结果如下:
为什么除了tip之外,其他的成员变量指针大小都是8,而不是4。其他成员变量指针里面还存了什么信息。希望用汇编解答一下,谢谢