在合格的声明者ID之后进行名称查找 [英] Name lookup after qualified declarator-id

查看:39
本文介绍了在合格的声明者ID之后进行名称查找的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

秒3.4.3/3说:

在声明符标识为限定标识的声明中,名称在声明的限定ID之前查找之前使用的定义名称空间范围;查找限定ID后面的名称在成员的类或名称空间的范围内.

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的代码示例:

There is a code example from 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__];

但是我认为这是不正确的,因为在封闭范围内可以找到在 XC :: arr [number] 中使用的不合格名称,但是在 XC :: arr [C:: number] 不在封闭范围内搜索 number .是错字吗?

But I think that it is not true because unqualified name used in the X C::arr[number] can be found in the enclosing scope, but the X C::arr[C::number] is not searching the number in the enclosing scopes. Is it a typo?

推荐答案

据我所知示例是正确的,并且直接从示例之前的段落中得出:

As far as I can tell example is correct and follows directly from the the paragraph before the example:

在声明符标识为限定标识的声明中,名称在声明的合格ID 前使用的定义名称空间范围

因此找到的 X 将是 :: X 而不是 C :: X ,因为它在合格ID之前

So the X found will be ::X and not C::X since it is before the qualified-id

和:

跟随名字的名字被限定为在成员的类或名称空间的范围内

所以 number 将是 C :: number ,因为它位于限定ID后面.

So number will be C::number since it is after the qualified-id.

这篇关于在合格的声明者ID之后进行名称查找的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆