Name lookup after qualified declarator-id

久未见 提交于 2021-02-09 12:49:08

问题


Sec. 3.4.3/3 said:

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.

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__];

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?


回答1:


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

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;

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

and:

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

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



来源:https://stackoverflow.com/questions/24104101/name-lookup-after-qualified-declarator-id

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!