下面代码是针对基类、派生类的构造丽数和析构西数调用顺字的训练,运行结果正确的是! class Base 泵 public: BaseO( cout <<"Base构造"<< end;} ~BaseOf cout <<"Base析构”<< endli ]; class Child: public Base public: Childo{ cout <<"Child构造"<<endl} ~Childoi cout <<"Child析构" <<endl;, void main© Child aChild;
时间: 2023-07-19 10:03:26 浏览: 64
在派生类的构造函数中调用基类的构造函数
下面是代码的正确版本:
```cpp
#include <iostream>
using namespace std;
class Base {
public:
Base() {
cout << "Base构造" << endl;
}
~Base() {
cout << "Base析构" << endl;
}
};
class Child : public Base {
public:
Child() {
cout << "Child构造" << endl;
}
~Child() {
cout << "Child析构" << endl;
}
};
int main() {
Child aChild;
return 0;
}
```
运行结果是:
```
Base构造
Child构造
Child析构
Base析构
```
阅读全文