How to declare an array of pointers to functions returning different types?

  • 3
    Counter-question: how are you going to call a function from this array? - VladD
  • while ((tmp = fun1 ())! = 0) {array_fun2 [tmp] ();} - TauCetiV
  • one
    use an array of structures with two fields, the first one of type int, where the "signature number" will be specified, and the second of type void* , where the pointer will be stored. - KoVadim
  • If you are given an exhaustive answer, mark it as correct (a daw opposite the selected answer). - Nicolas Chabanovsky

1 answer 1

The array is an array, indicating one type and no matter int char or int (*)(void) . But you can create an array of pointers to one type of function, and when called, specify another type

 int fun_0(int); int fun_1(int,int); int fun_2(int,int,int); int (*array_fun[])(int) = {fin_0,(int (*)(int))fin_1,(int (*)(int))fun_2}; int (*fun)(int,int) = (int (*)(int,int))array_fun[1]; *fun(3,5);