Hallo,
I am doing some operator overloading and found something in a book I want to ask about:
Why is there a & in front of the operator keyword?Code:Point &operator = (const Point &p);
Thanks :)
Printable View
Hallo,
I am doing some operator overloading and found something in a book I want to ask about:
Why is there a & in front of the operator keyword?Code:Point &operator = (const Point &p);
Thanks :)
Personally I prefer to put the & more to the left, like this:
...in which case it's easier to read that the operator returns a reference to a point (most likely itself, after the assignment)Code:Point& operator = (const Point& p);
If you were not actually confused by the syntax but rather was asking why the copy assignment operator returns a reference, the answer is that it is to facilitate operator chaining, e.g., a = b = c.
Ah, ok. Think I got it.
Working on a school assignment and dont want to use things I dont understand
Thanks :)