Why is there a priority for operators like static_cast?

According to cppreference.com, the priority level of the C ++ static_cast is 2 .

Why are these levels even defined? I can’t think of any reason. Can anyone provide an example?

+7
source share
2 answers

The standard does not define priority levels; they can be derived from grammar.

Like any other syntax function, static_cast takes place in this grammar. Since its use requires brackets, its operand expression can never be ambiguous, but this only means that it makes no sense to worry about getting the priority level for it from the grammar, and not that its place in the grammar itself is not makes sense. So the standard does nothing crazy here.

Which makes no sense that any source you specify listed a priority level for static_cast . This is not so, just pointless.

+4
source

The priority level of C ++ operators is 2

Who said that? The standard does not determine the priority of the operator. It defines grammar in a BNF-like notation.

+3
source

All Articles