Operator overloading in C++ and the ampersand

c++, class, operator-overloading

Solution

It's C++'s syntax for pass-by-reference & return-by-reference. It just means that the parameter is an alias of the object from the calling context, and not a copy, and, simillary, the returned object is actually `*this`, and not a copy.

Problem

Possible Duplicate: What's the ampersand for when used after class name like ostream& operator <<(…)? I am new to C++ and I have probably a very noobish question. I have seen a thing like this: ``` Vector3f & operator = (Vector3f & obj) { _item[0] = obj[0]; _item[1] = obj[1]; _item[2] = obj[2]; return *this; } ``` And I was wondering why is there an ampersand (&) after Vector3f. What kind of magic is it doing? I couldn't find any explanations anywhere. Most importantly, what is the difference between the thing above and ``` Vector3f operator = (Vector3f obj) { _item[0] = obj[0]; _item[1] = obj[1]; _item[2] = obj[2]; return *this; } ```

Original source

Related problems