0

help me

can anyone explain what is &obj in funtion?? class MyClass { public: MyClass() { regVar = 0; } private: int regVar; friend void someFunc(MyClass &obj); };

22nd Jun 2018, 6:23 AM
林冠渝
林冠渝 - avatar
2 Answers
+ 1
&obj is a pointer to the obj object. If you want to know more, you need to show us the code.
22nd Jun 2018, 10:20 AM
f3d0rov
f3d0rov - avatar
+ 1
Ok, someFunc takes MyClass object by reference. As it is friend function, it can access obj's private variables and functions. It takes a pointer to an object because we want to modify the original object but not its copy, as it happens if we're passing the object itself.
22nd Jun 2018, 1:01 PM
f3d0rov
f3d0rov - avatar