HP aC++/HP C A.06.25 Programmer's Guide
typename Keyword
Use the typename keyword in template declarations to specify that a qualified name
is a type, not a class member.
Usage
This construct is used to access a nested class in the template parameter class as a type
in a declaration within the template.
Example
template<class T>
class C1 {
// class details omitted
// T::C2 *p; // Problem: flagged as compile-time
// error. T is a type, but T::C2 is not.
// Message: ‘C2’ is used as a type, but
// has not been defined as a type.
typename T::C2 *p; // Solution: the keyword typename flags
// the qualified name T::C2 as a type.
};
class C {
// details omitted
class C2 {
//details omitted
};
};
int main ()
{
C1<C> c;
}
In a template, a name is not taken to be a type unless it is explicitly declared as one.
Ways to declare a name as a type include:
• Use it as the argument to the template (T below):
template<class T>
class C {
// Additional details omitted
};
• Use it as the name of the template (C below):
template<class T>
class C {
// Additional details omitted
};
196 Standardizing Your Code