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![]()
This is a discussion on Question about operator overloading within the C++ Programming forums, part of the General Programming Boards category; Hallo, I am doing some operator overloading and found something in a book I want to ask about : Code: ...
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.
C + C++ Compiler: MinGW port of GCC
Version Control System: Bazaar
Look up a C++ Reference and learn How To Ask Questions The Smart Way
Ah, ok. Think I got it.
Working on a school assignment and dont want to use things I dont understand
Thanks![]()