C ++ friend classes

Just trying to make sure that I understood friends correctly with this

class A
{
  friend class B;
  int valueOne;
  int valueTwo;
  public:
  int GetValueOne(){ return valueOne; }
}
class B
{
  public:
  A friendlyData;
  int GetValueTwo(){ return friendlyData.valueTwo; }
}
main()
{
  B myObject;
  myObject.friendlyData.GetValueOne(); // OK?
  myObject.GetValueTwo(); // OK?
}

As for this code, if we ignore the lack of initialization, then the two functions will basically be fine? And, besides, something like funky things, they should not be another way to get data from these classes ... Aside from this class B.Ahas no data available, just a member function.

+3
source share
2 answers

, main . : B::A, B::GetValueTwo A::GetValueOne. public . , , main.

+2

, GetValueX , . GetValueTwo() .

: .

0

Source: https://habr.com/ru/post/1775005/


All Articles