I am wondering if there is a way in C++ to write a function that will resolve object methods based on the method name alone (specific examples below). Run time or compile time resolution (such as templates) would both be acceptable. I have read a little bit about template metaprogramming, but I was hoping I might get some info as to whether that is even the appropriate direction for my problem before delving to deep into that.
Essentially, I am trying to write a function that will call non-static methods of a passed in object, such as this psuedocode:
exampleFunction(Object myObject, ObjectMethod myObjectMethod) {
// do some stuff here
myObject.myObjectMethod(arguments);
// do some more stuff here
}
In this case, I cannot hard-code a method into exampleFunction and simply have every object that I call it with have that method name. I must have the flexibility to call exampleFunction with a variety of methods, and have each of those methods properly resolve. Further, I must be able to resolve methods, and those methods must be non-static. In my case, I must be able to modify internal, private object members on the method call. Without going into the details, these constraints are an artifact of the system I am working on that I cannot change.
As I previously stated, both compile time and run time solutions are acceptable. So something like this with templates would work perfectly well in my case as well:
template <ObjectMethodName methodName>
exampleFunction(Object myObject) {
// do some stuff here
myObject.methodName(arguments);
// do some more stuff here
}
Any thoughts on whether this is possible, as well as information on possible implementation would be appreciated.