#define C ++ function arguments

I have a set of functions called in a common interface and I store these function pointers in a common container, so I have

typedef void(*CommandFunction)(const InputArgsMap &, const ArgumentMap *);

      

With that said, what is the best way to declare functions of this type without copy-pasting the argument list? I was thinking about implementing this with a help #define

, but is there any other way (better, oop)?

For example, is it possible to do something like

#define CMD_ARGS (const InputArgsMap &, const ArgumentMap *)
void _fcn_1(CMD_ARGS);
void _fnc_2(CMD_ARGS);

      

+3


source to share


1 answer


If you are declaring a function and not a pointer then enter an alias

typedef void CommandFunction(const InputArgsMap &, const ArgumentMap *);

      

then you can use it to declare functions

CommandFunction _fcn_1;
CommandFunction _fcn_2;

      



You will still have to write down the list of parameters when you define them.

is there any other (better, oop) way?

Overriding an abstract interface virtual member function might be better, depending on what you are doing. You will have to duplicate the parameter list if you do, which you find annoying; but in modern C ++ you can at least use the specifier override

to make sure you get it right.

+5


source







All Articles