Translations of this page?:

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 name 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

 
• • • IndexRecent changesRSScc