What is a friend function? in c++

0 votes
47 views
asked Dec 17, 2013 in C++ by joyl
Hi all

   What is a friend function? in c++

1 Answer

0 votes
answered Dec 17, 2013 by Ali Nawkhas Murad

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. 

...