这个例子:
++structure.field;
increments field
instead of giving "wrong type argument to increment" compiler error, although ++ and . operators are equaly hierarchized ergo: should've been executed from left to right.
我在这里想念什么吗?
这个例子:
++structure.field;
increments field
instead of giving "wrong type argument to increment" compiler error, although ++ and . operators are equaly hierarchized ergo: should've been executed from left to right.
我在这里想念什么吗?
.
has the higher precedence than the++
prefix increment operator, as seen on cppreference.com.Note that
.
and the++
postfix increment operator have the same precedence. Prefix and postfix have different precedence. If you wrotestructure.field++
then they'd have the same precedence and associativity would kick in to resolve the ambiguity as(structure.field)++
rather thanstructure.(field++)
.