source file name: friend1.cpp

#include<stdio.h>

#include<conio.h>

#include<iostream.h>

class Y;

class X

{

int a;

public:

void setno(int m)

{

a=m;

}

friend void min(X,Y);

};

class Y

{

int b;

public:


void setno(int n)

{

b=n;

}

friend void min(X,Y);

};

void min(X x, Y y)

{

if(x.a<y.b)

cout<<"\n minimum value is:   "<<x.a <<" from X class ";

else

cout<<"\n minimum value is:  "<<y.b << " from Y class;

}


void main()

{

clrscr();

cout<<"Friend function program: ";

X ob1;

Y ob2;

ob1.setno(10);

ob2.setno(50);

min(ob1,ob2);

getch();

}

output:

1. Friend function program: 

minimum value is: 10 from X class 

2. call ob1.setno(100); and ob2.setbo(15); 

Friend function program: 

minimum value is: 15 from Y class