I've seen people overload an assignment operator this way
Code:
class My_class {
public:
My_class() {}
My_class(int i) : data(i) {}
int get_data() const {
return data;
}
void set_data(int i) {
data = i;
}
const My_class& operator =(const My_class& my_class_obj) {
data = my_class_obj.data;
return *this;
}
private:
int data;
};
and it seems pointless, but I haven't been able to find a definitive answer -- is there any situation in which you would want the return type of = to be const My_class& (or even a situation in which this "constness" has any effect)?