cpp~7-8(虚基类的使用)
1 #include<iostream> 2 using namespace std; 3 4 class Base0 5 { 6 public: 7 int var0; 8 void fun0() 9 { 10 cout<<"Member of Base0"<<endl; 11 } 12 }; 13 14 class Base1:virtual public Base0 15 { 16 public: 17 int var1; 18 }; 19 20 class Base2:virtual public Base0 21 { 22 public: 23 int var2; 24 }; 25 26 class Derived:public Base1,public Base2 27 { 28 public: 29 int var; 30 void fun() 31 { 32 cout<<"Member fo Derived"<<endl; 33 } 34 }; 35 36 int main() 37 { 38 Derived d; 39 d.var0=2; 40 d.fun0(); 41 return 0; 42 }
不要让今天成为明天的遗憾!