Friend declaration in C++ - difference between public and private

BIU picture BIU · Jun 20, 2011 · Viewed 35.4k times · Source

Is there a difference between declaring a friend function/class as private or public? I can't seem to find anything about this online.

I mean the difference between:

class A
{
 public: 
      friend class B;
 };

and

class A
{
 private: //or nothing as the default is private
      friend class B;
 };

Is there a difference?

Answer

sharptooth picture sharptooth · Jun 20, 2011

No, there's no difference - you just tell that class B is a friend of class A and now can access its private and protected members, that's all.