析构栈中的内存
#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();
}我这个A a是在栈中分配的内存,我对它析构以后,怎么还在?
页:
[1]