您的位置:首页 > 编程语言 > C语言/C++

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

2011-12-30 11:43 211 查看
#include <iostream>

using namespace std;

class X
{
public:
int a;
};

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


linux 爆下面的错误

double free or corruption

windows直接爆异常

正确的写法

if (m_this)

{

delete m_this;

m_this = NULL;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: