首页 新闻 赞助 找找看

c++中成员变量指针的大小

0
[待解决问题]

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。其他成员变量指针里面还存了什么信息。希望用汇编解答一下,谢谢

chaoguo1234的主页 chaoguo1234 | 菜鸟二级 | 园豆:203
提问于:2013-07-07 02:52
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册