【发布时间】:2012-12-11 03:06:22
【问题描述】:
您会在this document 的第 937 页上找到以下代码:
template<class T> class Safe
{
T* p; // p points to a T allocated using new
public:
Safe() : p(new T) {}
~Safe() { delete p; }
Safe& operator=(const Safe& a) { *p = *a.p; return *this; }
// ...
};
看起来,p指向的对象会在上面的赋值运算符中泄露。
【问题讨论】:
标签: c++ memory-leaks assignment-operator