cpp~7-6:作用域分隔符的使用
1 //多继承同名隐藏 2 #include <iostream> 3 4 using namespace std; 5 6 class Base1 7 { 8 public: 9 int var; 10 void fun() 11 { 12 cout<<"Member of Base1"<<endl; 13 } 14 }; 15 16 class Base2 17 { 18 public: 19 int var; 20 void fun() 21 { 22 cout<<"Member of Base2"<<endl; 23 } 24 }; 25 26 class Derived:public Base1,public Base2 27 { 28 public: 29 /* int var; 30 void fun() 31 { 32 cout<<"Member of Derived"<<endl; 33 } 34 */ 35 using Base1::var; 36 using Base1::fun; 37 }; 38 39 int main() 40 { 41 Derived d; 42 Derived * p=&d; 43 d.var=1; 44 d.fun(); 45 { 46 d.Base1::var=2; 47 d.Base1::fun(); 48 49 p->Base2::var=3; 50 p->Base2::fun(); 51 } 52 return 0; 53 }
不要让今天成为明天的遗憾!