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{ 17 protected: 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 }
原文地址:https://www.cnblogs.com/Tobi/p/9249840.html
时间: 2024-10-02 05:28:26