Sign in to follow this  
MaulingMonkey

How to call a template function of a template argument?

Recommended Posts

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

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this