Heiko Wundram (Beenic) wrote, On 27.12.2007 16:21:
> Hey all!
> 
> I'm currently trying to implement (and use) a C++ member function template, 
> but GCC won't eat the code I feed it.
> 
> The problem is most probably related to the fact that the group of member 
> functions is only discriminated by return type (i.e., the template parameter 
> defines the return type), not by parameter (which could be inferred).
> 
> From what I gather, the C++ spec should allow the following code to work (the 
> following is simplified from what I have, but pretty much the same 
> syntactically):
> 
> """
> template <typename U>
> class Test
> {
> 
> public:
> 
>       template <typename V>
>       V test()
>               throw()
>       {
>               // Some stuff.
>       }
> 
> };
> 
> template <typename U, typename V>
> void test2()
>       throw()
> {
>       Test<V>* x = new Test<V>();
>       x->test<U>();
Change this to x->template test<U>(); For explanation see 14.2/4 of the year
2003 revision of the standard.

>       delete x;
> }
> 
> int main(int argc, char** argv)
> {
>       test2<int,short>();
> }
> """
> 
> gcc doesn't compile this code, no matter what I try to change the x->test<U> 
> expression to. It does compile the code if the type of x is not defined via a 
> template parameter in test2.
> 
> If this is against the specs, please tell me, otherwise, looking forward to 
> any hints on what may cause this!
> 

--
VH

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to