一元+指针 [英] Unary + on pointers

查看:114
本文介绍了一元+指针的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是浏览 C ++ 11草案标准,并发现以下令人困惑的说法(第13.6/8节):

I was just browsing through the draft of the C++11 standard and found the following puzzling statement (§13.6/8):

对于每种类型T,都有以下形式的候选运算符功能

For every type T there exist candidate operator functions of the form

T* operator+(T*);

应该如何理解指针上的一元+"运算符?在正常情况下,这只是空手而归吗?还是我在这里想念的更深层次?

How should this "unary +" operator on pointer be understood? Is this just a no-op in the normal case, which can nevertheless be overloaded? Or is there some deeper point I am missing here?

推荐答案

您的问题的答案只是您引用的引号上方的一页— §13.6/1:

The answer to your question is just a page above the quote you cited — §13.6/1:

在本节中指定了代表第5章中定义的内置运算符的候选运算符功能. 这些候选函数参与了13.3.1.2中所述的运算符重载解析过程,并且没有其他用途. [注意:因为内置运算符仅采用带有非类类型,并且仅当操作数表达式最初具有类或枚举类型时才发生运算符重载解析,只有当操作数具有用户定义的转换为类类型的类类型时,运算符重载解析才能解析为内置运算符适用于运算符的非类类型,或者当操作数具有可转换为适用于运算符的类型的枚举类型时.还应注意,本节中给出的某些候选运算符功能比内置运算符本身更宽松.如13.3.1.2中所述,在通过重载解析选择了内置运算符之后,该表达式要服从第5节中对内置运算符的要求,因此要遵守此处给出的任何其他语义约束.如果存在与内置候选运算符功能具有相同名称和参数类型的用户编写的候选,则内置运算符功能将被隐藏,并且不包含在候选功能集中. -尾注]

The candidate operator functions that represent the built-in operators defined in Clause 5 are specified in this subclause. These candidate functions participate in the operator overload resolution process as described in 13.3.1.2 and are used for no other purpose. [ Note: Because built-in operators take only operands with non-class type, and operator overload resolution occurs only when an operand expression originally has class or enumeration type, operator overload resolution can resolve to a built-in operator only when an operand has a class type that has a user-defined conversion to a non-class type appropriate for the operator, or when an operand has an enumeration type that can be converted to a type appropriate for the operator. Also note that some of the candidate operator functions given in this subclause are more permissive than the built-in operators themselves. As described in 13.3.1.2, after a built-in operator is selected by overload resolution the expression is subject to the requirements for the built-in operator given in Clause 5, and therefore to any additional semantic constraints given there. If there is a user-written candidate with the same name and parameter types as a built-in candidate operator function, the built-in operator function is hidden and is not included in the set of candidate functions. —end note ]

这篇关于一元+指针的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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