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

23rd May 2018, 12:51 PM
Pablo Palacios
Pablo Palacios - avatar
2 Respostas
+ 1
Can you please attach your code here?
23rd May 2018, 1:45 PM
$¢𝐎₹𝔭!𝐨𝓝
$¢𝐎₹𝔭!𝐨𝓝 - avatar
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.
23rd May 2018, 3:28 PM
Blank
Blank - avatar