简体   繁体   中英

Operator hierarchy in ++structure.field

The example:

++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.

Am I missing something here?

Prefix and postfix ++ have different precedence. . has the higher precedence than the prefix increment operator, as seen on cppreference.com .

来自 cppreference.com 的运算符优先级和关联性表的摘录

. and postfix increment have the same precedence. If you wrote structure.field++ then they'd have the same precedence and associativity would kick in to resolve the ambiguity as (structure.field)++ rather than structure.(field++) .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM