According to cppreference.com, the C++ static_cast operator’s level of precedence is 2.
Why are those levels even defined? I can’t think of any reason. Can anyone provide an example?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The standard doesn’t define precedence levels; these can be derived from the grammar.
Like any other syntactical feature,
static_casthas a place in this grammar. Because its use requires parentheses its operand expression can never be ambiguous, but that only means that it makes no sense to bother deriving a precedence level for it from the grammar, not that its place in the grammar itself is meaningless. Thus the standard is doing nothing crazy here.What’s pointless is that whatever source you cited listed a precedence level for
static_cast. It’s not wrong, it’s just pointless.