有人请解释一下。到目前为止,我知道,删除后我无法访问分配的内存。如果我错了,请纠正我。
#include <iostream>
using namespace std;
class A
{
int x;
public:
A()
{
x = 3;
cout<< "Creating A" <<endl;
}
~A()
{
cout<< "Destroying A" <<endl;
}
int getX()
{
return x;
}
};
int main(int argc, const char * argv[])
{
A* a = new A();
delete a;
cout<< a->getX()<<endl;
return 0;
}
输出显示如下!
Creating A
Destroying A
3
getX()
不明白删除后怎么打电话a