Hi. I am new to C++, coming from C# and Vb.NET. I have been trying to discover through book explanation and other online references exactly how to implement this friend functionality. I was able to declare and compile but now cannot access the friend function. Here is what I have.
You need to specify the namespace in front of your ctor, dtor and functions.
Also getHiddenvar is not a member function so you can't call it from an object.
How did you manage to compile ?
@Thomas1965 and @Repeater , I get that it works when the class and the implementations are all done inside the same file but I am trying to put my friend function inside TestClass.h. I get now that you don't implement it inside TestClass.Cpp but inside the file you wish to use it but when I remove the getHiddenVar from Testclass.Cpp and add it to my file containing my main() like so:
You need to declare the function outside the class in TestClass.h, in addition to being declared as a friend inside the class, otherwise you won't be able to call it from outside the class.