问题描述
秒。 10.2描述了成员名称查找规则:
The sec. 10.2 describes member name lookup rules:
10.2 / 3:
10.2 / 4:
请考虑以下两个示例:
class A
{
void foo(){ A::a; } //S(a, A)={ static const int a; }
static const int a = 5;
}
和
class A
{
int b[A::a]; //S(a, A) is empty and the program is ill-formed
static const int a = 5;
}
实际的S(f,C)计算规则是什么? / p>
What is the actual S(f, C) calculation rules and why?
推荐答案
对于这些代码片段
class A
{
void foo(){ A::a; } //S(a, A)={ static const int a; }
static const int a = 5;
};
class A
{
int b[A::a]; //S(a, A) is empty and the program is ill-formed
static const int a = 5;
};
您应该考虑部分中描述的名称查找3.4名称查找
。他们与你引用的引语没有什么共同点。虽然我可以显示什么是S(f,C)例如名称A :: a在第一类定义。所以S(a,A)只能从一个声明中得到。 static const int a = 5
you should consider the name lookup that is described in section 3.4 Name lookup
of the Standard. They have nothing common with the quotes you cited. Though I can show what is S(f, C) for example for name A::a in the first class definition. So S( a, A ) cosists only from one declaration static const int a = 5
在第二个类定义名称 A :: a
将不会被找到,因为它必须在其使用之前声明。
Take into account that in the second class definition name A::a
will not be found because it has to be declared before its usage.
另一个规则用于成员函数中的名称查找。
The other rule is used for the name lookup in member functions. In the first class definition name A::a will be found.
所有这一切都在我指出的标准的3.4节中描述。
All this is described in section 3.4 of the Standard as I pointed out.
对于您引用的短语,更合适的例子将是例如以下
As for the phrase you cited then the more appropriate example will be for example the following
struct A
{
void f( int );
};
struct B : A
{
using f;
void f( char );
};
在这种情况下,如果搜索名称f,那么S(f,B)将包含两个声明
In this case if the name f is searched then S( f, B ) will contain two declarations
using f; // or void f( int );
和
void f( char );
这篇关于成员名称查找规则的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!