Template params in C++ functions
Joe Buck
jbuck@synopsys.com
Fri Oct 30 02:40:00 GMT 1998
> When there will be support for C++ functions with template params
> in egcs?
There already is, however it conforms with the standard unlike 2.7.2.
> Example:
> ---------
> template <class ListType>
> void DeleteList (ListType *list) {
> ListType::ElementType *e;
> while ((e = list->GetFirst()) != NULL) {
> list->Remove (e);
> delete e;
> }
> }
You need to fix your code: the standard is designed to allow templates
to be parsed when first encountered. This means that you must use
the 'typename' keyword correctly to identify names that are types.
You don't have to do this for ListType, since it is a template argument,
but you do have to do it for ListType::ElementType. So the fix
is
typename ListType::ElementType *e;
> The above works in g++-2.7.2 but
> not in g++-2.8.1 or g++-egcs1.1.
2.7.2's template support was quite weak and deviated a good deal from
the standard (not its fault, the standard wasn't done yet).
More information about the Gcc
mailing list