* Template methods of a template class
@ 2004-10-06 14:11 Stuart Brooks
2004-10-06 14:30 ` Stuart Brooks
0 siblings, 1 reply; 2+ messages in thread
From: Stuart Brooks @ 2004-10-06 14:11 UTC (permalink / raw)
To: GNU GCC
[-- Attachment #1: Type: text/plain, Size: 898 bytes --]
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 '<'"
[-- Attachment #2: testprog.tgz --]
[-- Type: application/octet-stream, Size: 308 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: Template methods of a template class
2004-10-06 14:11 Template methods of a template class Stuart Brooks
@ 2004-10-06 14:30 ` Stuart Brooks
0 siblings, 0 replies; 2+ messages in thread
From: Stuart Brooks @ 2004-10-06 14:30 UTC (permalink / raw)
To: GNU GCC
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 '<'"
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2004-10-06 14:30 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-10-06 14:11 Template methods of a template class Stuart Brooks
2004-10-06 14:30 ` Stuart Brooks
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).