CPlusPlusThings/practical_exercises/10_day_practice/day5/调用规则/直接基类与间接基类.cpp
Light-City a4d828bb4c update
2020-04-06 00:57:02 +08:00

25 lines
470 B
C++

//当同时存在直接基类和间接基类时,每个派生类只负责其直接基类的构造。
#include <iostream>
using namespace std;
class A {
int x;
public:
A(int aa) {
x=aa;
cout<<"Constructing A"<<endl;
}
~A(){ cout<<"Destructing A"<<endl; }
};
class B:public A {
public:
B(int x):A(x){ cout<<"Constructing B"<<endl; }
};
class C :public B{
public:
C(int y):B(y){ cout<<"Constructing C"<<endl; }
};
int main(){
C c(1);
system("pause");
}