Hi
I have a class Number which represents a double with 2 digits after the dot.
Before I overloaded the = operator i ran some tests and got confused a little:
int main(int argc, char **argv) {
Number *w = new Number(1.111);
Number *q = new Number(3.444);
*w = *q;
std::cout << w->GetNumber() <<std::endl;
delete q;
std::cout << w->GetNumber() <<std::endl;
Number e(5.555);
Number t = e;
std::cout <<t.GetNumber() <<std::endl;
}
the output was
3.44
3.44
5.55
So my question is what is the default action of '=' on user defined objects when '=' is not overloaded?
i was under the impression that when writing:
*w = *q;
w points to q (like in java), however in my example i deleted q and w still had the correct values.
anyway, I got same results when i made assignments without overloading = and with overloading =.
Thanks everyone!