#include<iostream>
using namespace std;
class second; //forward declaration
class first
{
int x;
public:
void set_value(int a)
{
x=a;
}
friend void max (first, second);
};
class second
{
int y;
public:
void set value (int b)
{
y=b;
friend void max (first, second);
};
void max (first f, second s)
{
if (f.x>s.y)
cout<<"Maximum is"<<f.x;
else
cout<<"Maximum is"<<s.y;
}
int main()
{
first A;
second B;
A.set value (10);
B.set value (20);
max (A,B);//calling friend function
return 0
}
प्रोग्राम का आउटपुट होगा
Maximum is 20