C++学习(17)

 1 //类的成员变量的二义性问题
 2 #include<iostream.h>
 3 
 4 class A{
 5     protected:
 6         int a;
 7     public:
 8         A(int aa){
 9             a=aa;
10         }
11         ~A(){}
12 };
13 
14 class B1:public A{
15     protected:
16         int b1;
17     public:
18         B1(int aa,int bb1):A(aa){
19             b1=bb1;
20         }
21         ~B1(){}
22 };
23 
24 class B2:public A{
25     protected:
26         int b2;
27     public:
28         B2(int aa,int bb2):A(aa){
29             b2=bb2;
30         }
31         ~B2(){}
32 };
33 
34 class C:public B1,public B2{
35     protected:
36         int c;
37     public:
38         C(int aa1,int aa2,int bb1,int bb2,int cc):B1(aa1,bb1),B2(aa2,bb2){
39             c=cc;
40         }
41         ~C(){}
42         void PrintA(){
43             //cout<<"a="<<a<<endl;
44             cout<<"B1::a="<<B1::a<<endl;
45             cout<<"B2::a="<<B2::a<<endl;
46         }
47 };
48 
49 int main(){
50     C myC(1,2,3,4,5);
51     myC.PrintA();
52     return 0;
53 }

 

转载于:https://www.cnblogs.com/Tobi/p/9249838.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值