Sign in to follow this  
coderchris

template question

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
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

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