declaring a protected member function as friend

Stuart Brooks stuartb@cat.co.za
Tue Mar 22 13:20:00 GMT 2005


> This might answer to your question :
> "A name nominated by a friend declaration shall be
> accessible in the scope of the class containing the
> friend declaration." (ISO C++ standard 11.4.7)

To clarify, does this then mean that one can never allow a protected method
from class A to have friend access to class B? While this may be in the
standard, it doesn't make sense to me as the friend declaration is not
*calling* the protected method, but allowing the protected method friend
access to itself, which is completely different.

Also, does this then carry over to friend classes? As in ...

class A
{
public:
  void pubFunc();
protected:
  void protFunc();
};

class B
{
protected:
  friend class A;
};

Does this then mean that A::protFunc() doesn't have protected access to B?



More information about the Gcc-help mailing list