operators computing direction
Posted
by amiad
on Stack Overflow
See other posts from Stack Overflow
or by amiad
Published on 2010-04-12T10:59:18Z
Indexed on
2010/04/12
11:03 UTC
Read the original article
Hit count: 308
c++
Hi all!
I enqunterd something that I can't understand.
I have this code:
cout << "f1 * f1 + f2 * f1 - f1 / f2 is: "<< f1 * f1 + f2 * f1 - f1 / f2 << endl;
All the "f"s are objects, and all the operators are overloaded.
The weird this is that the first computarion is of the "/" operator, then the second "" and then the first "", after that - the operator "+" and at last - operator "-".
So basicly - the "/" and "*" worked from right to left, and the "+" and "-" operators worked from left to right.
I made another test... I checked this code:
cout << "f1 * f1 / f2 is: " << f1 * f1 / f2 << endl;
Now, the first operator was "*" and only then oerator "/". So now, it worked from left to right.
Can someone help me underatand why is there diffrence in the directions?
10X!
© Stack Overflow or respective owner