I have a macro that defines a function with a variable amount of arguments, the macro has some logic to decide which real function must be called. My current approach is the following:
#define FUNC(ret,args,args_call) \
ret my_func(args) { \
if( something ) other_func(args_call);\
return one_func(args_call);\
}
#define PARAM(...) __VA_ARGS__
I use it like that:
class AClass : public AInterface {
public:
FUNC(int,PARAM(int a, int b),PARAM(a,b))
};
I was wondering if there is a better way to do that.
Note: The declared (my_func
in my example) function will be used to reimplement a method from the super class, so the approaches using templates (the ones that I am aware of) will not solve my problem.
Edit2: Even using a proper variadic templated function, I still need the macro to declare the function because it overrides a function in the superclass.
#define FUNC(ret,args,args_call) \
ret my_func(args) { \
return proper_variadic_templated_function<ret>(args_call);\
}