class Person {
private:
string name;
int id;
public:
Person(string name, int id): name(name), id(id) {}
const Person& operator=(const Person &another) {
if (*this == another) // What is the problem here?
return *this;
// do copy
return *this;
}
};
I want to make a operator= overloading function. In the self assignment checking, if I do the checking as above, it will show error saying Invalid operands to binary expression (Person and const Person)
. But if I do this == &another
, no error will be shown.
Is the error saying that type of this
and type of another
are different? But if so, how come this == &another
will work?