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

来源:岁月联盟 编辑:exp 时间:2012-01-10

#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;
    }


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