When you have a friend class or function, you're accessing the private/protected members of another class. If you want access to the private/protected members of your own class, just make them public or write get/set functions.
Also, I'd suggest that you don't use all-caps names for your classes: all-caps is generally taken to mean a macro.
But this site says you can access the values of private/protected members in the same class using the friend keyword.
Does it?
In principle, private and protected members of a class cannot be accessed from outside the same class in which they are declared. However, this rule does not affect friends.
Friends are functions or classes declared with the friend keyword.
If we want to declare an external function as friend of a class, thus allowing this function to have access to the private and protected members of this class, we do it by declaring a prototype of this external function within the class, and preceding it with the keyword friend:
#include <iostream>
class FOX
{
public:
FOX(int x =0):p(x) {};
private:
int p;
//allow the non-member get_Fox_P() access to private parts.
friendint get_Fox_P(const FOX &f);
};
//This is NOT amember function of FOX
int get_Fox_P(const FOX &f)
{
return f.p;
}
int main()
{
FOX foo(10);
// This line will not compile because FOX::p is private
std::cout << foo.p << std::endl;
//as get_Fox_P() is a friend of FOX it has access to p
std::cout << get_Fox_P(foo) << std::endl;
return 0;
}