Friend function: Private members of a class cannot be accessed from outside the class. A non-member function cannot have an access to the private data of a class. Sometimes, two classes may need to share data in a common function. To access private data of more than one class in one common function, friend function is required. The common function is declared as a friend function of all those classes from which the function wants to share data.
Characteristics of friend function:
1. It is not the scope of the class to which it has been declared as friend.
2. Since it is not in the scope of the class it cannot be called using the object of that class.
3. It can be invoked like a normal function without the help of any object.
4. Unlike member functions, it cannot access the member names directly and has to use an object name and dot membership operator with each member name.
5. It can be declared either in the public or the private part of a class without affecting its meaning.
6. Usually it has the objects as the arguments.