consider the following example.
class A
{
int member;
};
class B
{
A& a_ref;
void manipulate()
{
a_ref.member++;
}
};
Now, obviously, B::manipulate
can not access a_ref
. I would like to allow (only) class B
to get (reference) to A::member
. I know that there exists friend
keyword, but I do not know how to use it properly. My intention is, that I could change B::manipulate
implementation to become this
int& A::only_B_can_call_this() // become friend of B somehow
{
return member;
}
void B::manipulate()
{
a_ref.only_B_can_call_this()++;
}