typename keyword

   
typename keyword Introduces a type name

  elaborated-type-specifier  := typename [::]  nested-name  ::  identifier  typename [::]  nested-name  :: [template]  template-id   using-decl  := using [typename] [::]  nested-name  ::  unqualified-id  ;  type-parm  := typename [  identifier  ] [=  id-expr  ] 

The typename keyword is used in two different situations:

  • When referring to a qualified member of a class template, the compiler cannot tell whether the name refers to a type, object, or function. Use typename before the qualified name to tell the compiler that it names a type.

  • In a template declaration, use typename to name a type parameter. In this context, class means the same thing as typename .

Example

 template<  typename  C>  typename  C::value_type checked_first(const C& c) {   if (not c.empty(  ))     return c[0];   throw std::out_of_range("container is empty"); } 

See Also

class , expression , template , type , using , Chapter 7

   


C++ in a Nutshell
C++ in a Nutshell
ISBN: 059600298X
EAN: 2147483647
Year: 2005
Pages: 270
Authors: Ray Lischner

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