描述
用C++实现类Base和Derived,使其能输出样例信息。
主函数里的代码已经给出,请补充完整,提交时请勿包含已经给出的代码。
int main() { Base b; Base *p = new Derived; delete p; return 0; }
输入
无
输出
输出样例信息
样例输入
样例输出
Base Construct
Base Constructor
Derived Constructor
Derived Destructor
Base Destructor
Base Destructor
代码测试:
#include<iostream> using namespace std; class Base{ public: Base(){ cout<<"Base Constructor"<<endl; } virtual~Base(){ cout<<"Base Destructor"<<endl; } }; class Derived : public Base{ public: Derived(){ cout<<"Derived Constructor"<<endl; } ~Derived(){ cout<<"Derived Destructor"<<endl; } }; int main() { Base b; Base *p = new Derived; delete p; return 0; }