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
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);
MagosX.com
Give a man a fish and you feed him for a day.
Teach a man to fish and you feed him for a lifetime.
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.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
Ah, ok. Think I got it.
Working on a school assignment and dont want to use things I dont understand
Thanks