This definition
struct A { struct B; };
Defines struct A with a declaration of a nested structure B 1 . The full name of B is A::B , you can say that B is inside the "namespace" of A Then this:
struct A::B : A {
Is the definition A::B , but the only one : indicates that it is derived from A
Now the interesting part is A::B::A::B Cut it up:
A::B stands for nested structure.A::B::A accesses the name of the entered class A inside B Injection is related to inheritance.A::B::A::B will again introduce the nested structure B into A
And you can continue ad-infinitum, or at least until your compiler fulfills its translation limit 2 .
Exciting intellectual exercise, but avoid like the plague in real code.
[class.qual] / 1 explains how the search works
If the qualified identifier nested name qualifier assigns a class, the name specified after defining the nested qualifier name in the class scope ([class.member.lookup]), except as listed below. The name should represent one or more members of this class or one of its base classes (section [class.derived]).
And the above text allows us to name the base class, because [class] / 2
The class name is also inserted into the scope of the class itself; this is known as the name of the introduced class. For access verification, the name of the entered class is treated as if it were the public name of the member.
The above clearly says that when you run the full name with A:: you can specify a member or base class. Since A has no reason, you can only specify A::B ("member type"). But A::B also assigns a class. Therefore, we can specify the base or its part using A::B:: , which allows us to call A::B::A Now rinse and repeat.
<sub> 1 - Pay attention to this completely different B Not at all related to global struct B
2 - recommended minimum 256 in accordance with [implimits] /2.36
sub>
StoryTeller Nov 29 '17 at 6:48 2017-11-29 06:48
source share