继承类调用顺序

 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              

 

转载于:https://www.cnblogs.com/zhaojiedi1992/archive/2012/12/17/142857_12_12_17-3.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值