how to declare an array of function pointers?
C programmer's answer to this question:
use cdecl.
cdecl> declares a functional as a pointer to function (int, pointer to int) return double
double (* functable) (int, int *)
cdecl> declares a functional as an array of 17 pointers to a function (int) that returns double
double (* functable [17]) (int)
Note that functions are automatically converted to function pointers, in the same sense that arrays decay into pointers. You do not need a and take the address of the function to put it in the pointer.
If you're in C ++, this may help use std :: map <YourFunctionPointerType> instead of an array, since you still want to display strings ...
OO approach:
Use polymorphism instead. It does not immediately solve your problems, but there is a good chance that if you do this, it makes sense to have a class for each function.
Note that vtable is essentially a table of function pointers.
source share