标签:
代码:
1 #include <iostream> 2 #include <string> 3 #include <cstdio> 4 5 using namespace std; 6 7 class A{ 8 public: 9 virtual ~ A(){}; 10 virtual void funcA(){}; 11 }; 12 class B{ 13 public: 14 virtual void funcB(){}; 15 }; 16 class C:public A,public B{ 17 public: 18 }; 19 20 int main(int argc,char* argv[]){ 21 22 C c; 23 A* pA = &c; 24 B* pB = &c; 25 C* pC = &c; 26 cout<<pA<<" "<<pB<<" "<<pC<<endl; 27 28 return 0; 29 }
输出:
0x7ffedb751c10 0x7ffedb751c18 0x7ffedb751c10
分析:
注意派生类对象的地址与第一个父类地址相同,与第二个父类地址不同。
标签:
原文地址:http://www.cnblogs.com/hu983/p/5505774.html