0

Why is the ampersand before obj for?

In the following code, why is it OK to add/remove the & before obj? MyClass operator+(MyClass &obj) { MyClass res; res.var= this->var+obj.var; return res; }

9th Feb 2020, 4:19 PM
Franklin Qin
Franklin Qin - avatar
3 Respuestas
+ 1
Thanks! So the difference is after we could change obj.var in the function and whether we could see the changed value after function call.
10th Feb 2020, 8:07 AM
Franklin Qin
Franklin Qin - avatar