Originally Posted by
laserlight
I think that what works well is the opposite: writing the copy assignment operator in terms of the copy constructor. Of course, you need to have a suitable destructor and swap function.
I tried this
Code:
class point{
public:
point(){;}
~point(){;}
point(const point&);
double x, y, z;
point &operator =(const point &right_side);
};
point &point::operator =(const point &rhs){
this(&rhs);
return *this;
}
point::point (const point &pt) {
*this = pt;
}
but it doesn't seem to work. Although the following does
Code:
class point{
public:
point(){;}
~point(){;}
point(const point&);
double x, y, z;
point &operator =(const point &right_side);
};
point &point::operator =(const point &rhs){
x = rhs.x;
y = rhs.y;
z = rhs.z;
return *this;
}
point::point (const point &pt) {
*this = pt;
}