+ 1

The Example In Lesson

" class MyClass { public: int var; MyClass() {} MyClass(int a) : var(a) { } MyClass operator+(MyClass &obj) { MyClass res; res.var= this->var+obj.var; return res; } }; " in this example, why do we need '&' ?

1st May 2018, 7:34 PM
Yucuklu Sumurta
Yucuklu Sumurta - avatar
2 ответов
+ 1
it is pass by reference. we do not need it for a simple operation like thst tho, but that may be just faster to do it that way (for PC, not for you). http://www.learncpp.com/cpp-tutorial/73-passing-arguments-by-reference/
1st May 2018, 7:49 PM
Paul
0
thanks!
1st May 2018, 7:50 PM
Yucuklu Sumurta
Yucuklu Sumurta - avatar