Jump to content
  • Advertisement
Sign in to follow this  
MaulingMonkey

How to call a template function of a template argument?

This topic is 5139 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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

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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!