No, you can't do this with macros, because macros are evaluated before function definitions are evaluated.
There are several facilities in c++ that allow choosing between a specialized behavior, and a general purpose behavior if the specialization does not exist. These work such that at the call site calls the most general function, but a specialized implementation is invoked based on the type of th object calling it.
For example
Code:class DefaultContext {}; struct ClsContext { //I'm only using a struct here to keep the example short. Cls * clsPtr; }; void mouseClick(DefaultContext) { mouseClick(); } void mouseClick(ClsContext context) { context.clsPrt->mouseClick(); } int main() { auto context = someFactoryToGetContext(); mouseClick(context); // calls the correct function depending on the context type. }