名称查找紧跟在限定的 declarator-id 之后 [英] The name lookup followed after qualified declarator-id
问题描述
我试图理解以下引用的含义 (3.4.3/3 N3797):
I'm trying to understand what does the following quote mean (3.4.3/3 N3797):
在qualified-id之后的名称在范围内查找成员的类或命名空间.
names following the qualified-id are looked up in the scope of the member’s class or namespace.
namespace A
{
class C
{
public:
static const int a=7;
static int b;
};
}
int A::C::b=a; //7
static int b;
的作用域仅由 b
的声明点后面的声明区域组成.其实:
The scope of the static int b;
consist only of the declarative region following by the b
's point of declaration. Actually:
在类中声明的名称的潜在范围不仅包括名称声明点之后的声明区域,但是也包括所有函数体、默认参数、异常规范和大括号或相等的初始值设定项该类中的非静态数据成员
The potential scope of a name declared in a class consists not only of the declarative region following the name’s point of declaration, but also of all function bodies, default arguments, exception-specifications, and brace-or-equal-initializers of non-static data members in that class
这意味着static const int a=7;
不属于static int b;
的范围.因此,在 int A::C::b=a;
中找不到 static const int a=7
.
This implies that static const int a=7;
does not belong to the scope of static int b;
. Hence the static const int a=7
cannot be found in the int A::C::b=a;
.
这是标准中的错字还是我的误解?
It is a typo in the Standard or it is my misunderstanding?
推荐答案
这意味着 static const int a=7;不属于范围静态 int b;.因此静态 const int a=7 不能在int A::C::b=a;.
This implies that static const int a=7; does not belong to the scope of static int b;. Hence the static const int a=7 cannot be found in the int A::C::b=a;.
没有.它准确地暗示了您可以在那里阅读的内容:在类中声明的名称的潜在范围还 包含非静态数据成员的函数体等.这与上面的引用并不冲突 - 静态数据成员的声明区域(和范围)仍然包含它本身声明的类的范围.
No. It implies exactly what you can read there: The potential scope of a name declared in a class also contains function bodies etc. of non-static data members. That does not conflict with the quote above that - the declarative region (and the scope) of a static data member still contains the scope of the class it was declared in itself.
您自己引用了相关部分:
You quoted the relevant part yourself:
在qualified-id之后的名称在范围内查找成员的类或命名空间
names following the qualified-id are looked up in the scope of the member’s class or namespace
因此,由于在此代码片段中
Therefore, since in this code-snippet
int A::C::b=a;
a
用在 declarator-id 之后,在类中查找并找到.
a
is used after the declarator-id, it is looked up in the class and found.
这篇关于名称查找紧跟在限定的 declarator-id 之后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!