Template methods of a template class

Stuart Brooks stuartb@cat.co.za
Wed Oct 6 14:30:00 GMT 2004


A bit more information...

It seems template methods of a normal class have the same problem

class MyClass
{
  template<class C> C convert();
};
MyClass m;
float f=m.convert<float>();

is not happy either, while the following works fine outside a class

template<class C> C standalone_convert();
float f=m.standalone_convert<float>();



----- Original Message -----
From: "Stuart Brooks" <stuartb@cat.co.za>
To: "GNU GCC" <gcc-help@gcc.gnu.org>
Sent: Wednesday, October 06, 2004 4:08 PM
Subject: Template methods of a template class


> Hi,
>
> I have a segment of code which compiles and runs fine under g++ 3.3.3 but
> not under 2.91.60 which is unfortunately what I am stuck using for the
time
> being. I have given a *very* artificial example below (also in .cpp file
> attached) but the crux is that I can't seem to explicitly specify the
> template parameters for a template function within a template class in
> 2.91.60.
>
> Does anyone know if this is a limitation of the template code in the
earlier
> g++ or is there some trick to getting this to work? Any help would be
> appreciated...
>
> Regards
>  Stuart
>
>
> >>>> EXAMPLE
>
> template<class T> class MyTemplate
> {
>  public:
>
>   template<class C> C convert();
>   T value;
> };
>
> template<class T> template<class C> C MyTemplate<T>::convert() { return
> (C)value; }
>
> ...
>
> MyTemplate<int> base_template;
> base_template.value=100;
>
> float f=base_template.convert<float>();
>
> * The error is "syntax error before '<'"
>



More information about the Gcc-help mailing list