I am overloading operator '/'. when I divide object 'a' with object 'b' (under main), object 'a' is changed to 2, instead of equaling 7, as it was previously to the division. Is this an error? If not, why is the 'a'=2 and not 7?
#include <iostream>
using namespace std;
class OO{
int x;
int y;
public:
OO(){x=y=0;}
OO(int i, int j){x=i;y=j;}
OO operator+(OO ob){
OO temp;
temp.x=x+ob.x;
return temp;
}
OO operator=(OO ob){
x=ob.x;
return *this;
}
OO operator/(OO ob){
x=x/ob.x;
return *this;
}
OO operator++(){
OO temp;
temp.x=++x;
return temp;
}
void show(){
cout<<x<<endl;
}
};
int main() {
OO a(6,2);
OO b(3,2);
b.show();
a.show();
OO c = a + a;
c.show();
++a;
a.show();
c = a / b;
a.show();//why is this 'a' = 2, instead of 7?
c.show();
c=b=a;
c.show();
}