证同测试解决自我赋值的问题。
Test& Test::operator=(const Test& rhs)
{
if (this == &rhs) return *this;
delete pb;
pb = new Bitmap(*rhs.pb);
return *this;
}
异常处理(如执行new时可用空间不足)可以用copy-and-swap技术解决,同时可以解决自我赋值问题。
void swap(Test& rhs)
{
………………
}
Test& Test::operator=(const Test& rhs)
{
Test tmp(rhs);
swap(tmp);
return *this;
}