Friend Function

Friend Function :

  • A friend function of a class is defined outside that class’ but it has access to all private and protected members of the class.
  • Though it appear in the class definition, friends are not member functions.
  • A friend keyword is used to make any function or class friend.
e.g.

OUTPUT:

Average is :50
  • A class can also be declared friend of its all member function are to be made friend of any class.
e.g.
 

OUTPUT :

Name is :Arjun
Roll no. is :121
Average is :50

Leave a Reply

Your email address will not be published. Required fields are marked *