Home >> Sem 2 >> C++ programs >> FREIND
/* Write a Program to implement friend function */
#include<iostream.h>
#include<conio.h>
class test
{
int a,b,ans;
public :
test(int p,int q)
{
a = p;
b = q;
}
void show()
{
cout<<" "<<a<<" + "<<b<<" = "<<ans<<endl;
}
friend void sum(temp);
};
class temp
{
int a,b;
public:
temp(int p,int q)
{
a = p;
b = q;
}
};
void sum(test &t1)
{
t1.ans = t1.a + t1.b;
}
void main()
{
int n1,n2;
clrscr();
cout<<"Enter two integer Values : ";
cin>>n1>>n2;
test t1(n1,n2);
sum(t1);
t1.show();
temp tt(50,50);
// sum(tt);
// tt.show();
getch();
}