Back: The mutable Keyword
Forward: Runtime Type Identification (RTTI)
 
FastBack: Runtime Type Identification (RTTI)
Up: Changeable C++
FastForward: Compiler Quirks
Top: Autoconf, Automake, and Libtool
Contents: Table of Contents
Index: Index
About: About this document

16.2.8 The typename Keyword

The typename keyword was added to C++ after the initial specification and is not recognized by all compilers. It is a hint to the compiler that a name following the keyword is the name of a type. In the usual case, the compiler has sufficient context to know that a symbol is a defined type, as it must have been encountered earlier in the compilation:

 
class Foo
{
public:
  typedef int map_t;
};

void
func ()
{
  Foo::map_t m;
}

Here, map_t is a type defined in class Foo. However, if func happened to be a function template, the class which contains the map_t type may be a template parameter. In this case, the compiler simply needs to be guided by qualifying T::map_t as a type name:

 
class Foo
{
public:
  typedef int map_t;
};

template <typename T>
void func ()
{
  typename T::map_t t;
}


This document was generated by Gary V. Vaughan on May, 24 2001 using texi2html