gpt4 book ai didi

c++ - 符合条件的声明符 ID 后的名称查找

转载 作者:太空狗 更新时间:2023-10-29 21:42:57 24 4
gpt4 key购买 nike

秒。 3.4.3/3 说:

In a declaration in which the declarator-id is a qualified-id, names used before the qualified-id being declared are looked up in the defining namespace scope; names following the qualified-id are looked up in the scope of the member’s class or namespace.

有来自 3.4.3/3 N3797 的代码示例:

class X { };
class C {
class X { };
static const int number = 50;
static X arr[number];
};
X C::arr[number];// ill-formed:
// equivalent to: ::X C::arr[__C::number__];
// not to: C::X C::arr[__C::number__];

但我认为这不是真的,因为可以在封闭范围内找到 X C::arr[number] 中使用的非限定名称,但是 X C::arr[C::number] 未在封闭范围内搜索 number。是打错了吗?

最佳答案

据我所知,示例是正确的,并且直接遵循示例之前的段落:

In a declaration in which the declarator-id is a qualified-id, names used before the qualified-id being declared are looked up in the defining namespace scope;

因此找到的 X 将是 ::X 而不是 C::X 因为它在 qualified-id 之前

和:

names following the qualified-id are looked up in the scope of the member’s class or namespace

所以 number 将是 C::number 因为它在 qualified-id 之后。

关于c++ - 符合条件的声明符 ID 后的名称查找,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24104101/

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