Page 111 - DCAP404 _Object Oriented Programming
P. 111
Object-oriented Programming
Notes //member functions;
friend <return_type> <fname>(class first, class second. . ..);
};
The following program demonstrates the use of the friend function which is friendly to two
classes. The function seem to calculate the sum of two objects is declared friendly in both the
classes.
#include <iostream.h>
#include <conio.h>
class two;
class one
{
intx;
public:
void getdata()
{
cout <<“Enter the value for x “;
cin >>x;
}
void disp()
{
cout<< “The value of x entered is “<< x <<“\n”.
}
friend int sum( one,two);
};
class two
{
inty;
public:
void getdata()
{
cout <<“Enter the value for y “;
cin>>y;
}
void disp()
{
cout<< “The value of y entered is”<< y<< “\n”;}
friend int sum(one, two);
};
104 LOVELY PROFESSIONAL UNIVERSITY