How to create an array of function pointers in C / C ++

    3 answers 3

    void (*pfn_MyFuncType[10])(char * str, int len); 

    or

     void (**pfn_MyFuncType)(char * str, int len); 

      You must declare a new type - a pointer to a function. This is done by simply declaring a function pointer. Next, you need to declare an array of type pointer to the function. For example:

       typedef void (*pfn_MyFuncType)(char * str, int len); pfn_MyFuncType * myFuncTypeArray; // или pfn_MyFuncType myFuncTypeArray[10]; 

        In the style of c ++ 11 <

         #include <vector> #include <iostream> #include <functional> void foo(int i) { std::cout << i << '\n'; } int main() { std::vector<std::function<void(int)>> vfunc; vfunc.push_back(foo); vfunc[0](1); return 0; }