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); };
2 odpowiedzi
+ 1
&obj is a pointer to the obj object. If you want to know more, you need to show us the code.
+ 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.