标签:
重载赋值操作符时需要考虑自赋值问题,否则可能会导致严重错误。
Fred& operator= (const Fred& f)
{
// Bad code: Doesn‘t handle self-assignment!
delete p_; // Line #1
p_ = new Wilma(*f.p_); // Line #2
return *this;
C++ Super-FAQ 『Assignment Operators』
标签:
原文地址:http://www.cnblogs.com/yanxingyoudao/p/5230357.html