Can I have a static array of pointers to functions in C++?
c, c++, pointers
Solution
Should be made as simple as possible, but not simpler:
typedef int (*t_MyFunc)();
t_MyFunc g_MyFuncArray[5];
And `g_MyFuncArray` can be static if you wish (but you should not if you want a global variable):
static t_MyFunc g_MyFuncArray[5];
In a header file you should write:
extern t_MyFunc g_MyFuncArray[5];
But don't forget to omit the `static` keyword in a `.cpp` file in this case.
Problem
I need a global array of function pointers, and came up with this: ``` static int (*myArray[5])(); ``` if i am right, this is "a global array of pointers to functions returning int". Is that right? Or is it "an array of pointers to functions returning a static int". I just need a quick answer.