Template params in C++ functions
Martin von Loewis
martin@mira.isdn.cs.tu-berlin.de
Thu Oct 29 11:52:00 GMT 1998
> template <class ListType>
> void DeleteList (ListType *list) {
> ListType::ElementType *e;
Strictly speaking, this is invalid C++. ListType::ElementType is
considered as an object (not as a type), and the whole thing is
considered as a multiplication expression. Then, `e' is not declared,
and the code is in error.
To declare ElementType as a type, you need to write
template <class ListType>
void DeleteList (ListType *list) {
typename ListType::ElementType *e;
...
Earlier g++ versions accepted your code since ûtypenameë is a recent
addition to C++.
egcs sometimes silently assumes 'typename' when no confusion is
possible.
Regards,
Martin
More information about the Gcc-bugs
mailing list