0
votes

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 keyword typename 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 or A<T> because A or A<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?

1
Perhaps you can expand on your question with a few examples; I don't think it's very clear as stated (I certainly don't understand what you are asking). (Also, I think your comments in the cited text may be on the wrong lines; they don't make sense where they are currently placed. I don't have a PDF of the standard handy to check).James McNellis
ISO/IECINTERNATIONAL STANDARD 14882 Second edition 2003-10-15 Programming languages — C++ Langages de programmation — C++BE Student
@BES: I guess you tried to post a link but couldn't because you don't have enough points. That's a good thing, because pirating the standard on this site would be uncool.Potatoswatter
Why do you always think that everything is the standard is wronge, false, ... ?Cedric H.
Without even looking at the statement: Yes, of course it's true! That's the C++ standard; with the exception of a few defects (most of which were likely found during the decade the standard has been out there), whatever it says is the truth by definition.sbi

1 Answers

1
votes

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 the class {} block, so the only way to refer to them is with a qualified-id, which requires typename.

template< typename >
class base1
    { typedef int type1; };

class base2 
    { typedef int type2; };

template< typename A >
class derived
    : base1< A >, base2 {
    typename base1< A >::type1 x;
    type2 y;
};