Ok, I'm working on a book and trying to learn how to overload a C ++ statement. I created a BigInt class that takes one int (initially set to 0) for the constructor. I overloaded the + = method and it works fine in the following code:
BigInt x = BigInt(2);
x += x;
x.print( cout );
The code will be output 4. So, then I worked on overloading the global + operator with the following code:
BigInt operator+(const BigInt lhs, const BigInt rhs)
{
BigInt returnValue(lhs);
returnValue += rhs;
return returnValue;
}
This is also great for the following code:
BigInt x = BigInt(1);
BigInt y = BigInt(5);
BigInt z = x + y;
z.print();
This prints 6. However, when I try to execute the following code, it just doesn't work. The book does not explain very well and implies that it should just work.
BigInt x = BigInt(1);
BigInt z = x + 5;
z.print();
1. , z 1, 6. googled stackoverflow, - , . , . !
user131441