分类: C/C++
2009-04-21 10:20:22
a[i]=a[j];
*p=*q;
都潜在自我赋值。在类的继承中也有可能出现。
void dosomething(const Base& rb,Derived * pd);
rb和*pd有可能是一个对象
class Bitmap {....};
class Widget
{
private: Bitmap * pb;
};
Widget& Widget::operator=(const Widget& rhs)
{ if(*this=rhs) return *this; //处理代码
delete pb;
pb=new Bitmap(*rhs.pb);
return *this;
}
Widget& Widget::operator=(const Widget& rhs)
{ Bitmap *tmp=new Bitmap(*rhs.pb);
delete pb; pb=tmp;
return *this; }
Widget& Widget::operator=(const Widget& rhs)
{ Bitmap *tmp=pb;
pb=new Bitmap(*rhs.pb);
delete tmp;
return *this;
}