#include<iostream>
using namespace std;
class A{
public:
A(int i){
a=i;cout<<"con.A"<<endl;
}
void print(){
cout<<a<<endl;
}
~A(){
cout<<"des.A"<<endl;
}
private :
int a;
};
class B1:public A{
public:
B1(int i,int j):A(i){
b1=j;
cout<<"con.B1"<<endl;
}
void print(){
A::print();
cout<<b1<<endl;
}
~B1(){
cout<<"des.B1"<<endl;
}
private:
int b1;
};
class B2:public A{
public :
B2(int i,int j):A(i){
b2=j;
cout<<"con.B2"<<endl;
}
void print(){
A::print();
cout<<b2<<endl;
}
~B2(){
cout<<"des.B2"<<endl;
}
private:
int b2;
};
class C:public B1,public B2{
public:
C(int i,int j,int k,int l,int m):B1(i,j),B2(i,j),c(m){
cout<<"con.C"<<endl;
}
void print(){
B1::print();
B2::print();
cout<<c<<endl;
}
~C(){
cout<<"des.C"<<endl;
}
private :
int c;
};
int main(){
C c1(1,2,3,4,5);
c1.print();
}
C++多继承的二义性问题
最新推荐文章于 2022-08-27 17:28:49 发布