#include <iostream>
#include <string>
using namespace std;
class Base05{
public:
int m_a;
Base05(int a){
this->m_a = a;
cout << "父类的构造" << endl;
}
~Base05(){
cout << "父类的析构" << endl;
}
};
class Son05 : public Base05 {
public:
// 利用初始化列表,显示的调用父类的其他构造函数
Son05(int a) : Base05(a){
cout << "子类的构造" << endl;
}
~Son05(){
cout << "子类的析构"<< endl;
}
};
int main()
{
Son05 s1(10);
cout << s1.m_a << endl;
return 0;
}
05-20
9945
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
10-30
341
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
01-20
11-04
5981
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)