// Simple Overloading binary operator + in C++ example.
#include<iostream.h>
#include<conio.h>
class abc
{
int x;
int y;
public:
void getdata();
void display();
abc operator +(abc);
};
void abc::getdata()
{
cout<<"Enter value for x & y";
cin>>x>>y;
}
void abc::display()
{
cout<<"x= "<<x<<endl;
cout<<"y= "<<y<<endl;
}
abc abc::operator+(abc a1)
{
abc temp;
temp.x=x+a1.x;
temp.y=y+a1.y;
return(temp);
}
int main()
{
abc obj1,obj2,obj3;
obj1.getdata();
obj2.getdata();
obj3=obj1+obj2;
obj3.display();
getch();
}
No comments:
Post a Comment