binary operator overloding
#include<bits/stdc++.h>
using namespace std;
class item
{
int x,y,z;
public :
void get()
{
cout<<"Enter x : ";
cin>>x;
cout<<"Enter y : ";
cin>>y;
cout<<"Enter z : ";
cin>>z;
}
void show()
{
cout<<x<<" "<<y<<" "<<z<<endl;
}
item operator + (item b)
{
item temp;
temp.x=x+b.x;
temp.y=y+b.y;
temp.z=z+b.z;
return temp;
}
};
int main()
{
item a,b,c;
a.get();
b.get();
c=a+b;
a.show();
b.show();
c.show();
return 0;
}
0 Comments