gpt4 book ai didi

c++ - 歧义消解

转载 作者:太空狗 更新时间:2023-10-29 20:48:05 27 4
gpt4 key购买 nike

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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com