typename [C++ Reference]
Keywords: keywords,typename
Date: 2009-06-19T06:08:36-0700

[[typename]]
C++ Reference
Translations of this page?:

- en
- br-pt
- cn
- fr
- it
- jp
- pl
- ru
- tr

## typename

#### Specifying Type Parameters To Templates

In template argument lists typename can be used interchangeably with class to indicate type parameters. Although there is no difference to the compiler, Alexandrescu recommends using class when the template argument is expected to be a class or struct, and typename for other classes of types. This is purely to encourage source readability.

#### Disambiguating Dependent Names

The typename keyword is also used to indicate that a Dependent Names in a template definition refers to a type.

    struct Foo {
      typedef int Type;
    };

    template<class T>
    struct Bar {
      typedef typename T::Type BarType; // In a typedef
      void baz() {
         typename T::Type instance;     // In a declaration
      }
    };

    typedef Bar<Foo> FooBar;

Related Topics: class, template

Edit this page • Old revisions
• • • Login • Index • Recent changes • RSS • cc •