new int;中的new是操作符吗? [英] Is `new` in `new int;` considered an operator?

查看:66
本文介绍了new int;中的new是操作符吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

表达式 new int; int * x = new int; 新操作员"和新操作员"之间的区别?

The expression new int; such as in int * x = new int; is a new expression. The term "new operator" seems to be used interchangeably with "new expression", for example in this question : Difference between 'new operator' and 'operator new'?

说关键字 new 在新表达式中使用的是运算符吗?为什么或为什么不呢?

Is it correct to say that the keyword new as it is used in a new expression is an operator? Why or why not?

如果不是,是否有另一个理由来调用新表达式"new operator"?

If not, is there another justification for calling a new expression "new operator"?

我很难找到构成算子的权威定义.

I am having trouble finding an authoritative definition for what constitutes an operator.

我已经理解新操作员之间的区别,该操作员为对象和新表达";最终可能会称为 operator new .

I already understand the distinction between operator new which allocates memory for an object and "new expression" which may eventually call an operator new.

推荐答案

new 不被视为运算符.它也被认为不是不是运算符.

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

关于什么构成运算符",C ++标准确实含糊不清,甚至不一致.当列出运算符时(如在词汇化和预处理期间定义的那样),它将它们与标点符"一起列出.(类似()之类的东西,但总体上从来没有真正为标点符号提供任何规则.它列出了 new 作为关键字和运算符.列出了 sizeof ,但不在运算符集中,但后来将其称为运算符.

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.

这里的要点是,C ++标准委员会并没有过分关注将词法世界划分为操作符"或操作符".和非运营商".这是因为实际上没有任何需要.没有适用于所有运营商或所有非运营商的语法规则.重要集,例如 overloadable 运算符集,是分别给出的;一次给出诸如二进制算术表达式之类的语法规则.

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.

基本上,操作员"是指语言"不是对C ++语言形式上有意义的类别,因此任何分类答案都将基于其感觉"如何.您可以根据需要将其称为运算符,但也可以将其称为关键字(或标点符号!),并且语言标准也不会与您不同.

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.

这篇关于new int;中的new是操作符吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆