I think I am missing something obvious but I can't see what.
I am starting to create classes which require operator overloading. I don't understand one convention I am reading for overloading them: in the code below I am taking as an example the operator +=
. Now, in this example the operator overload is declared as a reference to an object of the class, but then the return statement de-references the pointer to the current object, so it should be returning its value (right?). To me this looks like a contradiction. I would actually expect the return
statement to return an address, not a value.
NewClass& NewClass::operator+=(...){
//some code here
return *this;
}
I have see this question regarding returning *this
and I understand the logic there, but that does not answer my lack of understanding on what I see as a contradiction between declaring a reference return and returning what seems a value.
How to properly interpret this code?