I've got a situation where I would like to create method pointers into objects which are all derived from a specific class, but where the exact type of the objects is not known by the caller of the method. The normal method for method pointers in C++ seems to always specify the exact object type of the containing method, for instance:
typedef void (MyClass::*MyClassMethod)(void *arg);
In my case, I'd like MyClass to be a base class, the actual objects would be derived from this class and the methods being referenced would be defined in the derived classes. You might say that this is exactly what virtual functions are for, but in this case the method name is not known by the caller either (it's complicated). I've tried a number of ways to get this work, but so far no luck. Is this even possible in C++11? I hope so, because it is the best solution I've found for this particular programming problem.
Aucun commentaire:
Enregistrer un commentaire