Defining friend classes and access sections

When defining a class as a friend's class, it matters in which section of the accessories definitions are placed, and if so, will it change the members that the friend has access to?

class aclass
{
private:
   // friend bclass;

public:
   // friend bclass;

protected:
   // friend bclass;
};

class bclass
{};
+5
source share
4 answers

Access specifiers do not apply to friend / Class functions.
You can declare a Friend function or class in any Access Specifier, and the function / class will still have access to all member variables (Public, Protected and Private) of this class.

+3
source

/ (, "aclass" ) . ( public/private/protected); :

class aClass
{
public: int pub;  void fun1() {}
protected: int pro; void fun2() {}
private: int pri;  aClass(const aClass& o);  
  friend void outsider ();  
};

outsider() , pro, pri, fun1, fun2; aClass ( ).

+2

- , . - :

class Elephants
{
 //friend void notAMemberFuncion(argument 123);

public:
// member functions;

protected:
// data members;
};
+1

-/ // , , / . / , .

+1

All Articles