I have an interface where I have to pass on member function pointer which are static cast'ed to a base pointer and behind our backs stored as a void pointer and invocation type (mfc message tables).
I have created a wrapper that does some exception handling (very simpel try/catch to catch std::runtime_error) since this is tedious and error prone to maintain in every single user callback.
So far, the following wrapper is actually working out fairly well (The idea is to grab the member function pointer directly as a value template parameter - in essence giving a member function wrapper for each and every callback function.):
class MyClass : public CWnd/*example*/{
public:
template<void (MyClass::*f)(CCmdUI*)>
void Dispatch(CCmdUI* pCmdUI) {
try {
(this->*f)(pCmdUI);
}
catch (std::runtime_error& e) {
//handle error
}
}
};
But in order to avoid having an explicit overload for each type of call - would it be possible to parametize the argument list ?
Illustration (note this doesn't work):
template<void (MyClass::*f)(Args...)>
void Dispatch(Args... args) {