三类如下:
class Base
{
public:
int var1;
};
class Base2
{
public:
int var2;
};
class Derive:public Base,public Base2
{
public:
int var3;
};
int main()
{
printf("%d %d %d %d %d", &Base::var1, &Base2::var2, &Derive::var1, &Derive::var2, &Derive::var3);
int Derive::* p = &Derive::var1;
Derive d;
d.var1 = 2;
printf("%d", d.*p);
}
输出结果为0 0 0 0 8 2
。&Derive::var1
我对and的结果感到困惑&Derive::var2
。为什么它们都相等0
而不是0
和4
分别?
注意:我用gcc4.7.1和vs2010测试过。结果是一样的。