Is `new` in `new int;` considered an operator?

new in new int is not considered to be an operator. It is also not considered to be not an operator.

The C++ standard is really vague, and even inconsistent, about what constitutes an ‘operator’. When listing operators (as defined during lexing and preprocessing), it lists them along with “punctuators” (things like (), but never really gives any rules for punctuators in general. It lists new as both a keyword and an operator. It lists sizeof in the set of keywords but NOT in the set of operators, but later refers to it as an operator.

The takeaway here is that the C++ standards committee is not overly concerned with separating the lexical world into “operators” and “non-operators”. This is because there isn’t really any need to. There’s no grammatical rules which apply to all operators or all non-operators. Important sets, like the set of overloadable operators, are given separately; grammatical rules for things like binary arithmetic expressions are given one at a time.

Basically, “operator” is not a category which is formally meaningful to the C++ language, so any categorical answer is going to be based on how it “feels”. You can call it an operator if you like, but you can also call it a keyword (or a punctuator!) and the language standard will not disagree with you.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)