#include<iostream>
#include<string>
using namespace std;
//继承中的构造和析构顺序
class Base1
{
public:
Base1()
{
cout << "Base1构造函数!" << endl;
}
~Base1()
{
cout << "Base1析构函数!" << endl;
}
};
//公共继承
class Son1 :public Base1
{
public:
Son1()
{
cout << "son1构造函数!" << endl;
}
~Son1()
{
cout << "son1析构函数!" << endl;
}
};
void test01()
{
//Base1 b;
Son1 s;
//继承中的构造和析构顺序如下
//先构造父类,再构造子类,析构的顺序与构造顺序相反
}
int main()
{
test01();
system("pause");//按任意键继续
return 0;//关闭程序
}
48类和对象-继承-构造和析构顺序
最新推荐文章于 2024-09-10 00:01:10 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)