CPlusPlusThings/practical_exercises/10_day_practice/day5/构造函数与析构函数/派生类构造函数调用顺序.cpp
Light-City a4d828bb4c update
2020-04-06 00:57:02 +08:00

46 lines
663 B
C++

#include<iostream>
using namespace std;
class A {
public:
A() { cout<<"Constructing A"<<endl;}
~A(){ cout<<"Destructing A"<<endl;}
};
class B {
public:
B() { cout<<"Constructing B"<<endl;}
~B(){ cout<<"Destructing B"<<endl;}
};
class C {
public:
C() { cout<<"Constructing C"<<endl;}
~C(){ cout<<"Destructing C"<<endl;}
};
class D:public C
{
public:
D() { cout<<"Constructing D"<<endl;}
~D(){ cout<<"Destructing D"<<endl;}
B b;
A a;
C c;
};
int main()
{
D d;
system("pause");
}
/*
Ö´ĐĐ˝ášűŁş
Constructing C
Constructing B
Constructing A
Constructing C
Constructing D
Destructing D
Destructing C
Destructing A
Destructing B
Destructing C
*/