Sunday, June 10, 2007

item 10

have assignment operators return a reference to *this

in built in types...assignment returns a reference to its left hand operand....so you wanna follow the convention

it applies to all operators not just assignment

class widget {
public:
widget& operator+=(const widget& rhs)
{...
return *this);
}

widget& operator=(int rhs)
{
....
return *this ;
}

};

unless you have a good reason for doing things differently, dont.


things to remember:
have assignement operator a reference to *this

No comments: