Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does it make a difference whether I put 'friend class xxxxx' in the public or private section?

class A1 { public: friend class B; }
class A2 { private: friend class B; }

Any difference?

like image 953
Kyle Avatar asked Apr 27 '10 14:04

Kyle


People also ask

Are friend functions public or private?

The friend function can be a member of another class or a function that is outside the scope of the class. A friend function can be declared in the private or public part of a class without changing its meaning. Friend functions are not called using objects of the class because they are not within the class's scope.

Where can I put my friend class?

Friends aren't in the class's scope, and they aren't called using the member-selection operators (. and ->) unless they're members of another class. A friend function is declared by the class that is granting access. The friend declaration can be placed anywhere in the class declaration.

Can friend classes access public members?

A friend function in C++ is defined as a function that can access private, protected and public members of a class. The friend function is declared using the friend keyword inside the body of the class.

Can friend classes access private members?

Friend class and function in C++ A friend class can access both private and protected members of the class in which it has been declared as friend.


1 Answers

No, access specificators have no effect on friend declaration.

like image 90
M. Williams Avatar answered Oct 11 '22 13:10

M. Williams