Scope resolution operator

后端 未结 2 870
眼角桃花
眼角桃花 2020-12-30 20:05

I accidentally happened to find this in one of the source codes I was looking at. So, I\'m giving a similar smaller example here.

In the file test.h:

<
2条回答
  •  一向
    一向 (楼主)
    2020-12-30 20:47

    To clarify the situation, as specified in §9/2:

    A class-name is inserted into the scope in which it is declared immediately after the class-name is seen. The class-name is also inserted into the scope of the class itself; this is known as the injected-class-name. For purposes of access checking, the injected-class-name is treated as if it were a public member name.

    However, as specified in §3.4.3.1/1:

    If the nested-name-specifier of a qualified-id nominates a class, the name specified after the nested-namespecifier is looked up in the scope of the class (10.2), except for the cases listed below.

    [ ... §3.4.3.1/2]:

    In a lookup in which the constructor is an acceptable lookup result and the nested-name-specifier nominates a class C:

    — if the name specified after the nested-name-specifier, when looked up in C, is the injected-class-name of C (Clause 9) [ ... ] the name is instead considered to name the constructor of class C.

    [ ... example: ]

    struct A { A(); };
    [ ... ]
    A::A a; // error, A::A is not a type name
    struct A::A a2; // object of type A
    

提交回复
热议问题