/*Program of BINARY OPERATOR OVERLOADING using member function*/
#include<conio.h>
#include<iostream.h>
class A
{
int a,b;
public:
void getdata(int p,int q)
{
a=p;
b=q;
}
void display()
{
cout<<“\na=”<<a<<“\nb=”<<b;
}
A operator+(A a1)
{
a1.a=a1.a+a;
a1.b=a1.b+b;
return a1;
}
};
int main()
{
A a1,a2,a3;
int f,g,h,i;
cout<<“\nEnter 2 numbers\n”;
cin>>f>>g;
a1.getdata(f,g);
a1.display();
cout<<“\nEnter 2 numbers\n”;
cin>>h>>i;
a2.getdata(h,i);
a3.display();
a3=a2+a1;
getch();
return 0;
}
OUTPUT :
Enter any number
5
Enter another number
7
Addition of these numbers = 12