Friend scope in C++

前端 未结 5 928
萌比男神i
萌比男神i 2020-11-28 06:05

If I have three classes, A, B, C. A and B are friends (bidirectionally). Also, B and C are friends (bidirectionally). A has a pointer to B and B has a pointer to C. Why can\

5条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-28 07:00

    This is all well summed-up here:

    What does it mean that "friendship isn't inherited, transitive, or reciprocal"?
    

    -->

    It means that classes derived from a friend class don't automatically become friends (do you trust the kids of your friends?), a friend of a friend doesn't automatically become a friend (do you trust the friends of your friends?), and that a class declaring another class as "friend" doesn't automatically become a friend of that class (do you trust anyone who calls you a friend?).

    from

    http://yosefk.com/c++fqa/friend.html#fqa-14.4

提交回复
热议问题