Jump to content
  • Advertisement
Sign in to follow this  
Toji

GCC compiler error with templates

This topic is 3411 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

I've been working on a C++ binding library for Squirrel recently, and have had a couple of people ask for GCC support. I'm not terribly familiar with GCC, but I thought I would give it a go. Fortunately, most of the errors were pretty easy to clean up, but I've got one that's got me stumped. With the following code, I get an error:
typedef int (*SQFUNCTION)(int);

template <class R>
class SqGlobal {
public:
	static int Func0(int vm) {
		// Doesn't really matter what's in here.
	}

	template <class A1, int startIdx>
	static int Func1(int vm) {
		// Doesn't really matter what's in here.
	}
};

template <class R>
SQFUNCTION SqGlobalFunc(R (*method)()) {
	return &SqGlobal<R>::Func0; // This works fine, for the record
}

template <class R, class A1>
SQFUNCTION SqGlobalFunc(R (*method)(A1)) {
	return &SqGlobal<R>::Func1<A1, 2>; // ERROR HERE
}
In visual studio this all works fine and dandy, but in GCC I get:
error: expected primary-expression before ',' token
error: expected primary-expression before ';' token
Both of which point at the line I've marked ERROR HERE. Wondering if it was me using an int in the template list that was problematic I removed it and got this instead:
error: expected primary-expression before '>' token
error: expected primary-expression before ';' token
So that's not it apparently. Now, correct me If I'm wrong but that seems like perfectly valid (if slightly complex) C++ code... I've been poking around for a while now, and can't figure out why it's complaining, much less how to fix it. Does anyone have anything that could point me in the right direction?

Share this post


Link to post
Share on other sites
Advertisement

template <class R, class A1>
SQFUNCTION SqGlobalFunc(R (*method)(A1)) {
return &SqGlobal<R>::template Func1<A1, 2>;
}


Share this post


Link to post
Share on other sites
Great, thank you!

*sigh* Visual Studio has spoiled me so badly... I really need to do more GCC work.

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!