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

前端 未结 30 2010
孤街浪徒
孤街浪徒 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:49

    As the reference for friend declaration says:

    The friend declaration appears in a class body and grants a function or another class access to private and protected members of the class where the friend declaration appears.

    So just as a reminder, there are technical errors in some of the answers which say that friend can only visit protected members.

提交回复
热议问题