How to call a template function of a template argument?

Started by
1 comment, last by MaulingMonkey 19 years, 6 months ago
After much ado, I finally tracked down the exact cause of the problem with my library... Here's the example code of what I'm trying to do:
class A
{
public:
	template < typename T > static void function( void ) {}
};
template < typename T , typename FunctionT > class B
{
public:
	void call_functon( void ) {
		FunctionT::function<T>(); //ERROR: syntax error before `;' token
	}
};
With or without instantiation, I get that error, and it has no helpful hints. The problem seems to occur because I'm trying to call a templatized function of a template argument (the problem disappears when I make A::function a non template and remove the template argument on the error-inducing line. For my library I solved the problem by making the entirety of class A templatized, and removing the templatization of function() within that class, aka like so:
template < typename T > class A
{
public:
	static void function( void ) {}
};
template < typename T , typename FunctionT > class B
{
public:
	void call_functon( void ) {
		FunctionT::function<T>(); //ERROR: syntax error before `;' token
	}
};
int main ( int argc , char ** argv )
{
    //old version: B<int,A> b;
    //new version:
    B<int,A<int>> b;
    b.call_function();
}
which although a bit uglier is acceptable for my situation (since B's 2nd parameter has a usually used default 2nd parameter anyways) but I'm wondering what the workaround is for a case where I NEED the members of (the equivilant of) class A to be templatized. edit: also, compiling this with GCC 3.3.1 on cygwin/win2k
Advertisement
You have to disambiguate the less than sign by using the keyword template (much like having to use typename to resolve ambiguity with non-type members).

void call_functon( void ){  FunctionT::template function<T>();}

Quote:Original post by Polymorphic OOP
You have to disambiguate the less than sign by using the keyword template (much like having to use typename to resolve ambiguity with non-type members).

*** Source Snippet Removed ***


Much thanks, that works. I tried throwing around the template keyword, but I tried putting it before that entire statement, not in the middle of. Thanks!

This topic is closed to new replies.

Advertisement