- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
void S(){}
struct S{};
int main(){
S();
}
在上面的代码中,main 中的表达式“S()”被视为函数调用表达式,而不是尝试创建类型为“S”的临时对象。
C++ 标准的哪一部分讨论了支持函数声明的此类表达式的解析?由于某种原因,我找不到它。
最佳答案
第 3.3.7/2 节
A class name (9.1) or enumeration name (7.2) can be hidden by the name of an object, function, or enumerator declared in the same scope. If a class or enumeration name and an object, function, or enumerator are declared in the same scope (in any order) with the same name, the class or enumeration name is hidden wherever the object, function, or enumerator name is visible.
那么在这种情况下你需要使用详细的类型说明符
3.4.4/1 详尽的类型说明符
An elaborated-type-specifier may be used to refer to a previously declared class-name or enum-name even though the name has been hidden by a non-type declaration (3.3.7). The class-name or enum-name in the elaborated-type-specifier may either be a simple identifer or be a qualified-id.
关于c++ - 歧义消解,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4094008/
我是一名优秀的程序员,十分优秀!