When should you use 'friend' in C++?

前端 未结 30 2185
孤街浪徒
孤街浪徒 2020-11-22 10:12

I have been reading through the C++ FAQ and was curious about the friend declaration. I personally have never used it, however I am interested in exploring the language.

30条回答
  •  再見小時候
    2020-11-22 10:58

    When implementing tree algorithms for class, the framework code the prof gave us had the tree class as a friend of the node class.

    It doesn't really do any good, other than let you access a member variable without using a setting function.

提交回复
热议问题