I have this problem when a pointer to a C ++ function is stored along with a set of arguments to call it so that it can be called later. The calling code does not know the type and arguments of the functions. Saving and calling function pointers and arguments is extremely critical in my application. The interface should look something like this:
void func( int a, char * b );
call_this_later( func, 5, "abc" );
A simple solution is to put all this information in a functor, requiring a different typedef for each function being called. C ++ 11 would allow me to do this using a variational pattern, so that's fine.
Since the type of functor is unknown at the point of call, it seems necessary to create a virtual base class for these functors and call functors using virtual function calls. The overhead of virtual functions + heap allocation is too high (I push the boundaries of the implementation of this idiom with minimal assembly instructions). So I need a different solution.
Any ideas?
source
share