• Advertisement
Sign in to follow this  

HOWTO: Register a template member func

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

Hi Everyone,

I'm trying to register a template member-function of a class that is not a template class. The class itself is a place-holder for different values. It's based on Ogre3D's Any. I would like to add it's template constructor as one of the registered functions if possible. How can I achieve this? I've looked into different options and all of them point to the class itself being a template type. Thanks for looking into this.

Cheers,
Vite Falcon

Share this post


Link to post
Share on other sites
Advertisement
A c++ template function becomes an ordinary function once you define the types, and you should register it as such.

I think I may not have understood your question. Perhaps you can show a little more on how this class is implemented so we can help you better.

Share this post


Link to post
Share on other sites
it's something like this...


class Any
{
public:
Any()
:mVal(0)
{
}

template <typename T>
Any(const T& val)
:mVal(new Value<T>(val))
{
}

template <typename T>
T& get()
{
return static_cast< Value<T> >(mVal)->valueHeld;
}
};

Share this post


Link to post
Share on other sites
Well, it is obviously not possible to register the template member without specifying the type, so there is really only two options:

1. Register the method for each possible type. This might be difficult as it is rarely possible to predict all possible types.

2. Register a wrapper function that takes the variable type, and then have the wrapper function invoke the correct template member based on the type it received from the script engine.


Regards,
Andreas

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement