Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
typename

typename

Tells the compiler that an unknown identifier is a type.


typename identifier;

Use this keyword only in template definitions.

This keyword must be used if the name is a qualified name dependent on a template argument; it is optional if the qualified name is not dependent. For more information, see Templates and Name Resolution.

typename can be used by any type anywhere in a template declaration or definition. It is not allowed in the base class list, unless as a template argument to a template base class.

template <class T>
class C1 : typename T::InnerType // Error - typename not allowed.
{};
template <class T>
class C2 : A<typename T::InnerType>  // typename OK.
{};

The typename keyword can also be used in place of class in template parameter lists. For example, the following statements are identical:

template<class T1, class T2>...
template<typename T1, typename T2>...

// typename.cpp
template<class T> class X
{
   typename T::Y m_y;   // treat Y as a type
};

int main()
{
}

Reference

C++ Keywords

Other Resources

Templates

Community Additions

ADD
Show:
© 2015 Microsoft