Search for a qualified class member name

Consider the following code snippet:

class A
{
    int b[A::a]; //1, error
    void foo(){ int b = A::a; } //2, ok
    static const int a = 5;
}

Paragraph 3.4.3.1/1 (Qualified Name Search, Class Members) said:

If a qualified identifier nested name qualifier assigns a class, the name specified after defining the nested qualifier name in the class scope (10.2)

This means that the name aafter the nested qualifier name in //1both and //2will be displayed in the scope of the class.

Paragraph 10.2 (Search for username) said:

10.2 / 2

The following steps determine the name lookup result for the member name f in class C.

10.2 / 3

The search set for f in C called S (f, C) ...

S (f, C) is calculated as follows:

10.2 / 4

C f, f, C, , .

:

, //1 //2 . . ?

. . :

class A
{
    int b[a]; //error
    void foo(){ int b = a; } //ok
    static const int a = 5;
}

, 3.4.1/7 3.4.1/8 ( ).

+4
2

, int b[A::a]; , A A. A , } . " ", , A.

, :

class A
{
    static const int a = 5;
    int b[A::a]; // OK
};

, . (, )

+4

int b[A::a]; A::a (3.3.7p1), void A::foo() (3.3.7p1b1):

1) , , , , , , ( ).

3.4.3.1p1 :

[...] [. (3.3.7). - ] [...]

, , , . , 3.3.2p5:

. [...]

, .

+3

Source: https://habr.com/ru/post/1545174/


All Articles