您需要 登录 才可以下载或查看,没有账号?立即注册
#include <iostream> using std::cout; using std::endl; class A { public: A(){} ~A(){ cout << "A::~A()" << endl; } void show() { cout << "A is alive!" << endl; } }; class B { public: B(A* pA){m_pA = pA;} ~B(){ if(m_pA) { delete m_pA; } } A* m_pA; }; void main() { A a; a.show(); B* pB = new B(&a); delete pB; a.show(); }
使用道具 举报
本版积分规则 发表回复 回帖后跳转到最后一页
小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)
GMT+8, 2024-11-23 07:36
Powered by Discuz! X3.4
© 2001-2023 Discuz! Team.