FRIEND1

Home >> Sem 2 >> C++ programs >> FRIEND1

/* Write a Program to use the friend function */
#include<iostream.h>
#include<conio.h>
class test
 {
   int a,b;
   public:
    test(int m,int n)
     {
       a = m;
       b = n;
     }
  friend int sum(test t1)
    {
      return t1.a+t1.b;
    }
};

void main()
{
 int a,b,ans;
 clrscr();
 test t1(10,20);
 ans = sum(t1);
 cout<<"\nAns : "<<ans;
 getch();
}