Friend function: The private members of a class cannot be accessed from outside the class but in some situations two classes may need access of each other‟s private data. So a common function can be declared which can be made friend of more than one class to access the private data of more than one class. The common function is made friendly with all those classes whose private data need to be shared in that function. This common function is called as friend function. Friend function is not in the scope of the class in which it is declared. It is called without any object. The class members are accessed with the object name and do membership operator inside the friend function. It accepts objects as arguments.
Example:
#include <iostream.h>
#include<conio.h>
class abc
{
int a;
public:
void get1()
{
cin>>a;
}
friend void add(abc,xyz);
};
class xyz
{
int a;
public:
void get1()
{
cin>>a;
}
friend void add(abc,xyz);
};
void add(abc a1,xyz x1)
{