I want to do something like this:
I want the user to provide a return type and an argument (there will always only be one) then I want the user to be able to provide the pointer of a function that matches this criteria. I will be using this to create a timed event.
The issue here is that usually with templates you must provide T and make a new class instance, however in this case I need it kind of a runtime. ex:
TimeEvent *explode = new TimeEvent(int (the return type),data (the argument), explodeFunc (the function pointer);
This would then create and set the function pointer. Then the caller simply does explode.call() to call it.
How could I achieve something like this?
Thanks
Well boost.function + boost.bind is something you can use for this:
and later…
But I am not sure if this is what you are looking for
Here a simple version without boost:
I hope you get the idea and can make it fit your needs.
HTH
Edit: Updated with templated return type.
* Made create_time_event a bit more user friendly