Name
typename keyword — Introduces a type name
Synopsis
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 astypename
.
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
Get C++ In a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.