Three classes as below:
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);
}
The output result is 0 0 0 0 8 2
. I am confused about the result of &Derive::var1
and &Derive::var2
. Why they are both equal 0
rather than 0
and 4
respectively ?
Note:I test it with gcc4.7.1 and vs2010. And the results are the same.