The typename keyword (C++ only)
Use the keyword typename if you have
a qualified name that refers to a type and depends on a template parameter.
Only use the keyword typename in template declarations
and definitions. Consider the following example:
template<class T> class A
{
T::x(y);
typedef char C;
A::C d;
}
The statement T::x(y) is ambiguous.
It could be a call to function x() with a nonlocal
argument y, or it could be a declaration of variable y with
type T::x. C++ compiler interprets this statement
as a function call. In order for the compiler to interpret this statement
as a declaration, you must add the keyword typename to
the beginning of T:x(y). The statement A::C
d; is ill-formed. The class A also refers
to A<T> and thus depends on a template parameter.
You must add the keyword typename to the beginning
of this declaration: typename A::C d;
You can also use the keyword typename in place of the keyword class in the template parameter declarations.