quote:Implementing assignment in term of the copy constructor.
Will be expensive in case of self-assigment (goes through unneeded copy).
Since vector::swap needs a non-const argument, I would have thought you''d want to remove the ''const''.
Why not:
class Cxxx{private: auto_ptr<vector<int> > vec; // other members herepublic: Cxxx() : vec(new vector<int>) {} Cxxx(const Cxxx& rhs) : vec(new vector<int>(*(rhs.vec))) // etc. {} void swap(const Cxxx& rhs) throws() { swap(vec, rhs.vec); // and any other members } Cxxx& operator=(const Cxxx& rhs) { if(this == &rhs) return *this; Cxxx temp(rhs); temp.swap(*this); return *this; }};
It doesn''t copy unnecessarily, and won''t fuck up the left-hand object unnecessarily.