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

## 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 on other sites
You could use boost::type_traits. In particular see remove_const and remove_reference.

##### Share on other sites
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 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 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 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.

1. 1
2. 2
Rutin
21
3. 3
JoeJ
18
4. 4
5. 5

• 14
• 39
• 23
• 13
• 13
• ### Forum Statistics

• Total Topics
631717
• Total Posts
3001878
×