Member variables† exist inside instances (objects). They are also called "instance variables". If there is no instance of the class, then there is no instance variable.
mSetValue
is a member variable of ScoreBoard
. Therefore ScoreBoard::mSetValue
instances exists only within an instance of ScoreBoard
.
how to properly set a friendship so ValueSet can get access to mSetValue array?
In function void ValueSet()
you don't have any instances of ScoreBoard
. You cannot access ScoreBoard::mSetValue
- regardless of its access specifier or friendship - because it doesn't exist. What you need is an instance of ScoreBoard
.
I use this function inside the ScoreBoard class so I can't create any instance of ScoreBoard inside it
Nothing prevents you from creating an instance of ScoreBoard
within a member function of ScoreBoard
. Although, within a member function of ScoreBoard
you already have access to an instance, which is pointed by this
, so there might be no need to create a new instance. What you should do depends on your intention.
Given your comment, I suspect that a member function would be more appropriate for you, rather than a free function.
† I use the generic term "Member variable" to refer non-static member variables for simplicity. Static member variables are different. They are also called class variables.