#include<iostream>
using namespace std;
class Base {
public:
Base() {
cout << "Base构造函数" << endl;
}
~Base()
{
cout << "Base析构函数" << endl;
}
};
class Son :public Base {
public:
Son() {
cout << "son构造函数!" << endl;
}
~Son()
{
cout << "son析构函数!" << endl;
}
};
void test01(){
Son s;
}
int main() {
test01();
system("pause");
return 0;
}
总结:继承中 先调用父类构造函数,再调用子类构造函数,析构顺序与构造相反