#include<iostream> using namespace std; class base { public: base(int k){a = k;}; virtual ~base() { cout<<"delete base"<<endl; }; protected: int a; public: void outputA(){cout<<"base:"<<a<<endl;} }; class child:public base { public: child(int k1,int k2); virtual ~child(); protected: int b; public: void outputB(){cout<<"child:"<<b<<endl;} }; child::child(int k1,int k2) :base(k1) { b = k2; } child::~child() { cout<<"deletechild"<<endl; } int main() { base* parent1; base* parent2; child* son; child* daughter; int* k1,k2; son = new child(1,2); parent1 = son; delete parent1; son->outputA(); son->outputB(); return 0; } #include<iostream> using namespace std; class base { public: base(int k){a = k;}; ~base() { cout<<"delete base"<<endl; }; protected: int a; public: void outputA(){cout<<"base:"<<a<<endl;} }; class child:public base { public: child(int k1,int k2); ~child(); protected: int b; public: void outputB(){cout<<"child:"<<b<<endl;} }; child::child(int k1,int k2) :base(k1) { b = k2; } child::~child() { cout<<"deletechild"<<endl; } int main() { base* parent1; base* parent2; child* son; child* daughter; int* k1,k2; son = new child(1,2); parent1 = son; delete parent1; son->outputA(); son->outputB(); return 0; }