Re: OT: C++ Template Functions
- From: Václav Haisman <V.Haisman@xxxxxxxxxx>
- Date: Thu, 27 Dec 2007 22:35:13 +0100
Heiko Wundram (Beenic) wrote, On 27.12.2007 16:21:
Hey all!Change this to x->template test<U>(); For explanation see 14.2/4 of the year
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>();
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
- References:
- OT: C++ Template Functions
- From: Heiko Wundram (Beenic)
- OT: C++ Template Functions
- Prev by Date: Re: OT: C++ Template Functions
- Next by Date: Re: printing boot probe messages
- Previous by thread: Re: OT: C++ Template Functions
- Index(es):
Relevant Pages
- Re: Member function pointer template argument
... What do you need the last template parameter for? ... template< typename
R, typename C, typename P1) ... Right, func is a variable, but Foo expects a type as second
template ... (comp.lang.cpp) - Re: Implementing a templated "round" function?
... At the moment i have two different implementations, ... I did add a second
template parameter S for the source type: ... > I could add a specialisation for
every combination of S and T, ... template <typename T, typename S> ... (comp.lang.cpp) - Re: Dealing with ad hominem attacks in comp.programming
... template <int N, int D> ... typedef rationaltype; ...
template <typename Lhs, typename Rhs> ... (comp.programming) - expression template help
... template < typename LeftOpd, typename Op, typename RightOpd> ...
(comp.lang.cpp) - Template member function cast bug in VC80SP1 (and more...)
... writing a small piece of metaprogramming code, we had to face some problems: ...
and both MAP_BASE and MAP define 'iterator' as ... we'll omit template parameters
from the text, ... template <typename S> ... (microsoft.public.vc.language)