- mongodb - 在 MongoDB mapreduce 中,如何展平值对象?
- javascript - 对象传播与 Object.assign
- html - 输入类型 ="submit"Vs 按钮标签它们可以互换吗?
- sql - 使用 MongoDB 而不是 MS SQL Server 的优缺点
在以下 C++11 代码中:
void f(int) {}
void f(double) {}
void (*p)(int) = f;
有两个功能。
第三个f
标识符是一个id-expression和p
的初始化器。
在 5.1.1p8 [expr.prim.general]/8 中它说:
The type of the [id-expression] is the type of the identifier. The result is the entity denoted by the identifier. The result is an lvalue if the entity is a function, variable, or data member and a prvalue otherwise.
鉴于 f
可能指代具有两种不同类型的两个不同实体,因此没有“实体”或“类型”。
标准中是否还有其他文本可以解决这种情况?
实现只是将其作为扩展消除歧义,还是在某个地方需要它? (如果没有其他文本,人们可能会争辩说,一个实现可能会拒绝 f id 表达式为模棱两可。)
最佳答案
标准(第 13.4 节)定义:
A use of an overloaded function name without arguments is resolved in certain contexts to a function, a pointer to function or a pointer to member function for a specific function from the overload set. A function template name is considered to name a set of overloaded functions in such contexts. The function selected is the one whose type is identical to the function type of the target type required in the context.
强调我的。
在引用之后,有一个与您的类似的示例(第 13.4/5 节):
int f(double);
int f(int);
int (*pfd)(double) = &f; // selects f(double)
int (*pfi)(int) = &f; // selects f(int)
就一元 &
而言,标准规定(在 § 5.3.1/6 并感谢 jogojapan ):
The address of an overloaded function can be taken only in a context that uniquely determines which version of the overloaded function is referred to.
但也可以省略(第 13.4/1 节):
The overloaded function name can be preceded by the & operator.
(再次强调我的)就像你在你的例子中所做的那样。
关于C++ 11初始化程序具有模棱两可的函数id表达式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20652424/
我从一所大学获得了一些示例代码,导入了项目并尝试运行测试:方法 assertThat(Integer, Matcher) 对于 MyClass 类型是不明确的 每个 assertThat 都被标记为红
关于将 iOS 应用程序迁移到 Swift 3.0 的过程。这是我面临的一个问题。 先上相关代码: let calendar = NSCalendar.current, calendCompo = c
我刚开始研究 Java 8 Lambda 功能。我在 Java 7 中编写了这段代码,并尝试在 lamdas 中执行它。请注意,最后一行会产生编译错误,因为重载的函数不明确。我明白原因。如何使用 la
如何优先(告诉编译器)使用“函数接收引用”(#B)而不是“函数接收值”(#A)? #include using namespace std; class Heavy{/* ...... */}; /
我正在使用 Google Map API V3 显示车辆行驶路径及其路线方向。但是通过谷歌方向图标,很难找到方向。下图解释更多 我看到了每个图标,它是 source 我找到了图片路径,是 http:/
我是一名优秀的程序员,十分优秀!