Re: Template methods of a template class

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxx>
To: "GNU GCC" <gcc-help@xxxxxxxxxxx>
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 '<'"
>


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux