#include <iostream> using namespace std; class A { public: A() { cout<<"A"; } ~A() { cout<<"~A"; } }; class B :public A { A *p; public: B() { cout<<"B"; p=new A(); } ~B() { cout<<"~B"; delete p; } }; int main() { B obj; return 0; }
运行结果:
知识点总结:
基类构造子类构造派生类构造派生类析构子类析构基类析构
原文地址:http://blog.csdn.net/ljd939952281/article/details/45787401