代码:
#include <iostream>
#include <string>
#include <cstdio> using namespace std; class A{
public:
virtual ~ A(){};
virtual void funcA(){};
};
class B{
public:
virtual void funcB(){};
};
class C:public A,public B{
public:
}; int main(int argc,char* argv[]){ C c;
A* pA = &c;
B* pB = &c;
C* pC = &c;
cout<<pA<<" "<<pB<<" "<<pC<<endl; return ;
}
输出:
0x7ffedb751c10 0x7ffedb751c18 0x7ffedb751c10
分析:
注意派生类对象的地址与第一个父类地址相同,与第二个父类地址不同。