operator overloading problem
Code:
#include<iostream.h>
#include<conio.h>
class location
{
public:
int xposition;
int yposition;
location(){}
location(int x, int y)
{
xposition=x;
yposition=y;
}
void show()
{
cout<<"Position x = "<<xposition;
cout<<"Position y = "<<yposition;
}
location operator+(location obj1)
{
location temp;
temp.xlocation=xlocation+obj2.x;
temp.ylocation=ylocation+obj2.y;
return temp;
}
};
void main()
{
clrscr();
location obj1(20,30);
location obj2(30,40);
location obj3;
obj1.show();
obj2.show();
obj3=obj1+obj2;
obj3.show();
getch();
}
I want to overload the operator + so addition can be done ;\ all the other code is fine but something is wrong in the operator+ fucntion.. can someone help? tanks