#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; }
运行结果:
知识点总结:
基类构造子类构造派生类构造派生类析构子类析构基类析构
时间: 2024-11-08 06:14:03