Reputation: 24771
I have overloaded both &
and *
. If I do this:
hgh=(xxx&yy)*vprod1;
It works as expected.
If I do this:
hgh=xxx&yy*vprod1;
I get a compiler error Invalid operands to binary expression.
How does the compiler read this: hgh=xxx&yy*vprod1;
-- Wouldn't it move from left to right, just as in the above example, with parenthesis? If the parenthesis were located in a different part of the expression, I can understand how there could be differences in how the compiler read it, but why would that apply here?
It should be worth noting that the return value of both overloads is identical, and returns the same type as xx
and yy
are in this calculation.
Upvotes: 3
Views: 108
Reputation: 258628
*
has higher precedence than &
, so it's applied first. Your expression is basically xxx & (yy * vprod1);
Upvotes: 8