首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

赋值函数为什么要释放原有的内存资源? delete []m_data;该怎么解决

2012-02-08 
赋值函数为什么要释放原有的内存资源? delete []m_data林锐的高质量程序设计中,第14章:赋值函数为什么要

赋值函数为什么要释放原有的内存资源? delete []m_data;
林锐的高质量程序设计中,第14章:
赋值函数为什么要释放原有的内存资源? delete   []m_data;

[解决办法]
接受新内容之前,当然要先把原来占有的东西善处理好啊。
[解决办法]
class Derived:public Base
{
public:
Derived ():p_test(NULL){}
virtual ~Derived()
{
if(p_test)
delete p_test;
cout < < "Derived::~Derived() " < < endl;
}
//...
private:
char *p_test;
};

热点排行