c++多次delete的后果及正确处理方法

2014-11-24 12:22:36 · 作者: · 浏览: 0

#include

using namespace std;

class X
{
public:
int a;
};

int main(void)
{
X *x = new X;
cout< delete x;
cout< //多次delete 会爆异常
//delete x;
system("pause");
return 0;
}

linux 爆下面的错误
double free or corruption
windows直接爆异常
正确的写法
if (m_this)
{
delete m_this;

m_this = NULL;
}


摘自 工作记录--创造或收集原创