Friday, April 20, 2012

Why Operator overloading behaves so strange

Hello Friend the output of the below program is so strange. I am not getting the reason.enter image description here



#include <iostream>
using namespace std;

class xyz
{
private:
int ab, cd;
public:
xyz()
{

}
xyz(int i, int j)
{
ab = i;
cd = j;

}
xyz operator+(xyz);
void show()
{
cout << ab << " .... "<< cd;
}

};
xyz xyz :: operator +(xyz ob)
{
xyz temp;
temp.ab = ab + temp.ab;
temp.cd = cd + temp.cd;
return temp;
}

int main()
{
// xyz xy, yz;

xyz xy(2, 3);
xyz yz(4, 5);
xy = xy + yz;

xy.show();
return 0;
}




No comments:

Post a Comment