gpt4 book ai didi

c++ - 使用 C++20 using-enum-declaration 进行二义性名称查找

转载 作者:行者123 更新时间:2023-12-03 15:41:08 24 4
gpt4 key购买 nike

考虑以下带有 C++20 的代码片段 using-enum-declaration :

namespace A { enum A {}; };

using namespace A;
using enum A;
gcc-trunk rejects它与:
<source>:4:12: error: reference to 'A' is ambiguous
4 | using enum A;
| ^
<source>:1:20: note: candidates are: 'enum A::A'
1 | namespace A { enum A {}; };
| ^
<source>:1:11: note: 'namespace A { }'
1 | namespace A { enum A {}; };
| ^
<source>:4:12: error: 'A' has not been declared
4 | using enum A;
| ^
但是,msvc 接受 它。有趣的是,如果我为 enum A 添加命名空间限定符:
namespace A { enum A {}; };

using namespace A;
using enum A::A;
gcc 接受 这一次,但是 msvc rejects它与:
<source>(4): error C2872: 'A': ambiguous symbol
<source>(1): note: could be 'A'
<source>(1): note: or 'A::A'
哪个编译器是对的?

最佳答案

MSVC 在这里是正确的。第一种情况是仅类型查找(因为它被认为是精心设计的类型说明符),因此它会忽略命名空间并通过 using 指令查找枚举。在第二种情况下,以下 ::允许找到命名空间,所以它是模棱两可的。

关于c++ - 使用 C++20 using-enum-declaration 进行二义性名称查找,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67096550/

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