继承类调用顺序
1 #include<iostream.h> 2 class A 3 { 4 private: 5 int a; 6 public: 7 int Get(){cout<<"A.Get()被调用!"<<endl;return a;} 8 }; 9 class B1:virtual public A 10 { 11 private: 12 int b1; 13 public: 14 int Get(){cout<<"B1.Get()被调用!"<<endl;return b1;} 15 }; 16 class B2:public A 17 { 18 private: 19 int b2; 20 public: 21 int Get(){cout<<"B2.Get()被调用!"<<endl;return b2;} 22 }; 23 class C:public B1,public B2 24 { 25 private: 26 int c; 27 public: 28 int Get(){cout<<"C.Get()被调用!"<<endl;return c;} 29 }; 30 void show(A &str) 31 { 32 cout<<str.Get()<<endl; 33 } 34 int main() 35 { 36 A a,*p; 37 B1 b1; 38 B2 b2; 39 C c; 40 p=&a; 41 show(a); 42 p=&b1; 43 show(b1); 44 p=&b2; 45 show(b2); 46 // p=&c; 47 //show(c); 48 return 0; 49 } 50
posted on 2012-12-17 17:10 LinuxPanda 阅读(261) 评论(0) 编辑 收藏 举报