cpp/language/injected-class-name

The injected-class-name is the unqualified name of a class within the scope of said class.

In a, the injected-class-name can be used either as a template name that refers to the current template, or as a class name that refers to the current instantiation.

Explanation
In a class scope, the name of the current class is treated as if it were a public member name; this is called injected-class-name. The point of declaration of the name is immediately following the opening brace of the class definition.

Like other members, injected-class-names are inherited. In the presence of private or protected inheritance, the injected-class-name of an indirect base class might end up being inaccessible in a derived class.

In class template
Like other classes, class templates have an injected-class-name. The injected-class-name can be used as a template-name or a type-name.

In the following cases, the injected-class-name is treated as a template-name of the class template itself:


 * it is followed by
 * it is used as a
 * it is the final identifier in the of a friend class template declaration.

Otherwise, it is treated as a type-name, and is equivalent to the template-name followed by the template-parameters of the class template enclosed in.

Within the scope of a class or, when the injected-class-name is used as a type-name, it is equivalent to the template-name followed by the template-arguments of the class template specialization or partial specialization enclosed in.

The injected-class-name of a class template or class template specialization can be used either as a template-name or a type-name wherever it is in scope.

A lookup that finds an injected-class-name can result in an ambiguity in certain cases (for example, if it is found in more than one base class). If all of the injected-class-names that are found refer to specializations of the same class template, and if the name is used as a template-name, the reference refers to the class template itself and not a specialization thereof, and is not ambiguous.

injected-class-name and constructors
Constructors do not have names, but the injected-class-name of the enclosing class is considered to name a constructor in constructor declarations and definitions.

In a qualified name, if


 * name lookup does not ignore function names, and
 * lookup of in the scope of the class  finds its injected-class-name

the qualified name is always considered to name 's constructor. Such a name can only be used in the declaration of a constructor (e.g. in a friend constructor declaration, a constructor template specialization, constructor template instantiation, or constructor definition).