父类和成员类的构造函数和析构函数顺序
#include"student.h"
#include <iostream>
#include <string>
using namespace std;
class Person
{
public:
int a;
Person()
{
cout << "Person构造" << endl;
}
~Person()
{
cout << "Person析构函数" << endl;
}
};
class son2
{
public:
son2()
{
cout << "son2构造" << endl;
}
~son2()
{
cout << "son2析构" << endl;
}
int c;
};
class son :public Person
{
public:
son()
{
cout << "son构造" << endl;
}
~son()
{
cout << "son析构" << endl;
}
son2 s;
int d;
};
void test01()
{
son SON;
}
int main()
{
test01();
system("pause");
}
直接贴图
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/3f658753361d8c62095ad40be3b43e18.png)
理解
做一个类,由里到外构造,销毁一个类,由外到里销毁。