16.2.8 The typename Keyword

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


GNU Autoconf, Automake and Libtool
GNU Autoconf, Automake, and Libtool
ISBN: 1578701902
EAN: 2147483647
Year: 2002
Pages: 290

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net