8

Does it matter where in a class a friend clause is placed (i.e. within the protected block as opposed to the private block)?

Qix - MONICA WAS MISTREATED
  • 14,451
  • 16
  • 82
  • 145

1 Answers1

10

No it does not.

class X
{
public:
    friend class A;
private:
    friend class B;
protected:
    friend class C;
};

All three classes are now friends of X and share the exact same priviliges.

A good convention is to group all friend declarations together for visibility, but that's just style.

11.4 Friends

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 or public (9.2) portion of the class member-specification.

Luchian Grigore
  • 253,575
  • 64
  • 457
  • 625
  • 1
    I'll add a convention of mine which is to put it in the private block as a reminder when looking at it of "who can touch this part" – mark Sep 27 '12 at 12:06
  • 2
    @mark: I put it in the `private` part, but at the top of the class (right after the `{`) as a reminder to all readers that some may bypass the public interface hereafter listed. – Matthieu M. Sep 27 '12 at 14:00
  • 1
    I put it in the `public` part since that's often the only part that other devs read. – Fraser Sep 28 '12 at 01:26