CPlusPlusThings/practical_exercises/10_day_practice/day5/虚拟继承/虚基类调用次序(重要).cpp
Light-City a4d828bb4c update
2020-04-06 00:57:02 +08:00

32 lines
578 B
C++

//ÖØÒª!!!
#include <iostream>
using namespace std;
class A {
int a;
public:
A(){ cout<<"Constructing A"<<endl; }
};
class B {
public:
B(){ cout<<"Constructing B"<<endl;}
};
class B1:virtual public B ,virtual public A{
public:
B1(int i){ cout<<"Constructing B1"<<endl; }
};
class B2:public A,virtual public B {
public:
B2(int j){ cout<<"Constructing B2"<<endl; }
};
class D: public B1, public B2 {
public:
D(int m,int n): B1(m),B2(n){ cout<<"Constructing D"<<endl; }
A a;
};
int main(){
D d(1,2);
system("pause");
return 0;
}