This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Template params in C++ functions


> 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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]