Friend Function Explained With Simple Example
A Friend function is a function defined outside the class, but it has access to all private and protected members of the class. To declare a friend function, it’s prototype must be declared inside the class, preceding it with keyword “friend”. For eg:
class Demo
{
private:
int m;
int y;
public:
friend int sum (Demo d);
void print_val ();
Demo (int m, int y);
};