0 votes
50 views
asked in C++ by
Hi all

   What is a friend function? in c++

1 Answer

0 votes
answered by

In general an object's attributes should be hidden from the outside. Sometimes, however, other non-member functions need to be able to access the private members of a class. In this case, the non-member function must be designated as a friend function of the class. Thus the friend function be able to access all members of the object, even protected members of the base class of the object. 

The friend function declaration form is as shown below: 

friend return-type function-name(parameter list); 

Of course the implementation can be done outside the class. 

Categories

...