虚基类
MADE
玩个基巴
写了半天
浏览器停止响应
然后
写的东西没了
的东西没了
东西没了
西没了
没了
了
!!!爆炸!!!
只有最后一丢丢代码了
1 #include<iostream> 2 using namespace std; 3 4 class A 5 { 6 public: 7 int a; 8 void disp() 9 { 10 cout<<"Member of A: a= "<<a<<endl; 11 } 12 }; 13 14 class B1:virtual public A 15 { 16 public: 17 int b1; 18 }; 19 class B2:virtual public A 20 { 21 public: 22 int b2; 23 }; 24 25 class C:public B1,public B2 26 { 27 public: 28 int c; 29 void dispc() 30 { 31 cout<<"Member of C: c= "<<c<<endl; 32 } 33 }; 34 35 int main() 36 { 37 C c; 38 c.a=1; 39 c.b1=2; 40 c.c=3; 41 c.disp(); 42 43 return 0; 44 }
1 #include<iostream> 2 using namespace std; 3 4 class A 5 { 6 public: 7 A(int i):a(i){} 8 int a; 9 void disp() 10 { 11 cout<<"Member of A: a= "<<a<<endl; 12 } 13 }; 14 15 class B1:virtual public A 16 { 17 public: 18 B1(int j):A(j){} 19 int b1; 20 }; 21 class B2:virtual public A 22 { 23 public: 24 B2(int j):A(j){} 25 int b2; 26 }; 27 28 class C:public B1,public B2 29 { 30 public: 31 C(int j):A(j),B1(j),B2(j){} 32 int c; 33 void dispc() 34 { 35 cout<<"Member of C: c= "<<c<<endl; 36 } 37 }; 38 39 int main() 40 { 41 C c(3); 42 c.a=1; 43 c.b1=2; 44 c.c=3; 45 c.disp(); 46 47 return 0; 48 }
v、