This is the statement from ISO C++ Standard 14.6/6:
Within the definition of a class template or within the definition of a member of a class template, the keyword
typename
is not required when referring to the unqualified name of a previously declared member of the class template that declares a type. The keywordtypename
shall always be specified when the member is referred to using a qualified name, even if the qualifier is simply the class template name. [Example:template<class T> struct A { typedef int B; A::B b; // ill-formed: typename required before A::B void f(A<T>::B); // ill-formed: typename required before A<T>::B typename A::B g(); // OK };
The keyword typename is required whether the qualified name is
A
orA<T>
becauseA
orA<T>
are synonyms within a class template with the parameter list<T>
. ]
Is this statement is true while inheritance?
If yes, can anyone explain this?
I checked with inner class; it is accepted? But I am unable to check with inheritance?
Yes, that is equally true of inherited members.
The keyword
typename
is required for members of base templates, but not base classes in general. The reason it is required for base templates is that their members are not automatically brought into the scope of theclass {}
block, so the only way to refer to them is with a qualified-id, which requirestypename
.