考虑以下程序
#include<iostream>
using namespace std;
class ClassA
{
public:
virtual ~ClassA(){};
virtual void FunctionA(){};
};
class ClassB
{
public:
virtual void FunctionB(){};
};
class ClassC : public ClassA,public ClassB
{
};
void main()
{
ClassC aObject;
ClassA* pA = &aObject;
ClassB* pB = &aObject;
ClassC* pC = &aObject;
cout<<"pA = "<<pA<<endl;
cout<<"pB = "<<pB<<endl;
cout<<"pC = "<<pC<<endl;
}
pA,pB,pC 应该相等,但结果是
pA = 0031FD90
PB = 0031FD94
PC = 0031FD90
为什么 pB = pA + 4?当我改变
class ClassA
{
public:
virtual ~ClassA(){};
virtual void FunctionA(){};
};
class ClassB
{
public:
virtual void FunctionB(){};
};
至
class ClassA
{
};
class ClassB
{
};
结果是
pA = 0030FAA3
pB = 0030FAA4
PC = 0030FAA3
pB = pA + 1?