Polymorphic function pointers

Hi,

In my game engine, I have an object hierarchy consisting of objects that inherit my base class STObject. STObject can handle registering of parameters (to make my game object parameters editable in my game editor) and it also handles (de)serialization of parameters.

In STObject, I have a method called
 
registerParameter(STParameterPointer parameter, const std::string& name, const std::string& description)


that lets STObject subclasses register their parameters. STParameterPointer is in fact a boost::variant, that can store pointers to all types that I use in my STObjects.

Now, instead of registering a variable directly, I'd like to store a pointer to get/set functions. For example, instead of doing something like

registerParameter(&position, "name", "description")

I want to be able to do

registerParameter(&MySTObjectSubclass::pos(), &MySTObjectSubclass::setPos, "name", "description");

I'm using C++11 and I've had a look at std::function. However, a function pointer stored in that way does not work polymorphically, which means that I can't just store a new type "STObject::setIntFunction" : I would have to create one type in my variant for each STObject subclass that wants to register a pair of getter/setters.

I'd appreciate any help on how to achieve what I want to do. If my question is unclear, please let me know and I'll explain further.

Thanks in advance!
Topic archived. No new replies allowed.