C++多重继承与虚基类
1.多重继承
多重继承就是一个派生类继承了多个基类。
I>初始化
i>通过成员初始化列表指定构造函数
class D : public B, public C {
private:
int a;
public:
D(int a1, int a2, int a3) : B(a1),C(a2),a(a3) {
cout << "D::D()" << endl;
}
};
ii>构造函数调用顺序
class B {
private:
int a;
public:
B(int a) : a(a){
cout << "B::B()" << endl;
}
void f() {
cout << "B::f() ------ a = " << a << endl;
}
};
class C {
private:
int a;
public:
C(int a) : a(a) {
cout << "C::C()" << endl;
}
void f() {
cout << "C::f() ------ a = " << a << endl;
}
};
class D : public B, public C {
private:
int a;
public:
D(int a1, int