OT: C++ Template Functions

Heiko Wundram (Beenic) wundram at beenic.net
Thu Dec 27 07:21:10 PST 2007


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>();
	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!

-- 
Heiko Wundram
Product & Application Development
-------------------------------------
Office Germany - EXPO PARK HANNOVER
 
Beenic Networks GmbH
Mailänder Straße 2
30539 Hannover
 
Fon        +49 511 / 590 935 - 15
Fax        +49 511 / 590 935 - 29
Mobil      +49 172 / 43 737 34
Mail       wundram at beenic.net


Beenic Networks GmbH
-------------------------------------
Sitz der Gesellschaft: Hannover
Geschäftsführer: Jorge Delgado
Registernummer: HRB 61869
Registergericht: Amtsgericht Hannover


More information about the freebsd-hackers mailing list