次のプログラムを検討してください
#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?