Jump to content
  • Advertisement
Sign in to follow this  
coderchris

template question

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

So, I have this very simple class used for my script system.
template <class A> class ExternalFunction1
{
public:

	ExternalFunction1(void (*func)(A)) : func(func) 
	{	}
	
	void run(ScriptStack &stack) 
	{
		A arg = *((A)stack.pop(sizeof(A)));
		func(arg);
	}

	void (*func)(A);
};
When I make an instance of this class like this: ExternalFunction<int> func(simpleFunction); It works just how I expect it to. Poping the argument off my stack and passing it to the actual function just fine. However, if I try to do something like this: ExternalFunction<const int&> func(simpleFunction); It wont compile, obviously because you cant instantiate something of type "const int&" So, my question is, is there any way using templates to kind of extract the "base type" of a template? So for example, If A was "const int&" what I want is "int" That way, I can extract my argument from the stack without the const and the & Sorry if thats a little confusing, let me know if I can explain it better. THanks

Share this post


Link to post
Share on other sites
Advertisement
thanks a bunch, that looks like exactly what I need.

I cant use boost in my project though, do you know how these might be implemented?

Share this post


Link to post
Share on other sites
If you "can't use boost", just copy and paste from the boost headers. remove_const and remove_reference are each only a few lines long.

Share this post


Link to post
Share on other sites
gotcha, I implemented it based on boosts implementations.

Now, this might be a silly question, but how exactly do I use for example remove_reference?

I have tried many different things just to test it like:

void test(const int& param)
{
remove_reference<const int&> plain_int = param;
...
}

but no luck

Share this post


Link to post
Share on other sites
If you clicked on the link I gave, and then clicked on the remove_reference link on that page, you'd see a table contained expressions and their results. The expressions all look something like remove_reference<int>::type.

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!