Friend function: – It is a non-member function. The use of friend function is to access the private member function of class or classes.
Note: – As we know that a non-member function (Which is not a part of the class) cannot access the private member of class but by using friend function we can access the private members of class. There are following rules to be followed.
- Friend function must be declare inside the class with friend keyword.
- In the formal argument of friend function the object should be their of the class.
- Friend function is not mutual.
- At the time of friend function definition friend keyword will not be use.
- A friend function can also be declared either in one class or more than one classes.
- Inside friend function. The member variables will be accessed with object name.
Note: – The use of friend function is very rare now a days because it exploit the data security.