摘要: 在实现operator=时考虑自我赋值是必要的就像 x=y ,我们不知道变量x与y代表的值是否为同一个值(把x和y说成是一个指针更恰当一点)。如下class bitmap{};class Widget{public: Widget& operator=(const Widget& rhn);private: bitmap *pb; //定义一个指针指向对分配的空间}第一版赋值函数:Widget& Widget::operator=(const Widget& rhs){ delete pb; pb = new bitmap(*rhs.pb); return th 阅读全文
posted @ 2013-05-09 23:15 onlycxue 阅读(385) 评论(0) 推荐(0) 编辑