C++學習(18)
阿新 • • 發佈:2018-07-01
alt col 二義性 pro AI clu IV src img
1 //類的成員函數的二義性問題 2 #include<iostream.h> 3 class B1{ 4 protected: 5 int b1; 6 public: 7 B1(int bb1){ 8 b1=bb1; 9 } 10 ~B1(){} 11 void print()const{ 12 cout<<b1<<endl; 13 } 14 }; 15 16 class B2{ 17protected: 18 int b2; 19 public: 20 B2(int bb2){ 21 b2=bb2; 22 } 23 ~B2(){} 24 void print()const{ 25 cout<<b2<<endl; 26 } 27 }; 28 29 class C:public B1,public B2{ 30 protected: 31 int c; 32 public: 33 C(int b1,int b2,int cc):B1(b1),B2(b2){ 34 c=cc; 35 } 36 ~C(){} 37 void print()const{ 38 cout<<c<<endl; 39 } 40 }; 41 42 int main(){ 43 C myC(1,2,3); 44 myC.B1::print(); 45 myC.B2::print(); 46 return 0; 47}
C++學習(18)