0
Error coding friend function example
in this code part "friend void someFunc(MyClass &obj);" i dont understand what is 'obj' and i can not run the code
2 Respostas
+ 1
Can you please attach your code here?
0
In this case "obj" is any object that is instantiated from the class "MyClass". That means the function "someFunc" takes an object from "MyClass" as its argument and is then able to perform operations on that object. The "&" means that the object is passed by reference, thus the function works directly with the object passed to it, not with a copy if it. So, for example, if you change the value of a variable of that object inside the function,
the change will remain.
If this is still not clear, you might want to re-visit earlier parts of the C++ course that deal with objects, etc.