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
|