//Program to illustrate the effect of overloading the comma operator.

| |


#include<iostream.h>
#include<conio.h>
class loc
{
int longitude,latitude;
public:
loc(){};
loc(int lg,int lt)
{ longitude=lg;
latitude=lt;
}
void show()
{ cout<<endl;
 cout<<longitude<<"\t";
cout<<latitude<<endl;
}
loc operator+(loc op2);
loc operator,(loc op2);
};
loc loc:: operator,(loc op2)
{
loc temp;
temp.longitude=op2.longitude;
temp.latitude=op2.latitude;
cout<<endl;
cout<<op2.longitude<<"\t"<<op2.latitude<<"\n";
return temp;
}
loc loc::operator+(loc op2)
{ loc temp;
temp.longitude=op2.longitude+longitude;
temp.latitude=op2.latitude+latitude;
return temp;
}

int main()
{ clrscr();
loc obj1(10,20),obj2(5,30),obj3(1,1);
obj1.show();
obj2.show();
obj3.show();
obj1=(obj1, obj2+obj3,obj3);
obj1.show();
getch();
return 0;
}
<