friend
子句在类中的位置是否重要(即在 protected
block 内而不是 private
block 内)?
最佳答案
不,它没有。
class X
{
public:
friend class A;
private:
friend class B;
protected:
friend class C;
};
所有三个类现在都是 X
的 friend 并且共享完全相同的特权。
一个好的约定是将所有友元声明组合在一起以提高可见性,但这只是风格。
11.4 好友
9) A name nominated by a friend declaration shall be accessible in the scope of the class containing the friend declaration. The meaning of the friend declaration is the same whether the friend declaration appears in the
private
,protected
orpublic
(9.2) portion of the class member-specification.
关于c++ - friend 声明的放置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12620908/