I have an array of 6 function pointers:
int (*arrayOfFunPointers[6])();
What I want to do now, is to allocate that array in heap
Because I create the array in a function and return a pointer to that array:
int (*(*fun2())[6])(){
int (*funPointer)();
int (*arrayOfFunPointers[6])();
int (*(*pointerToArrayOfFunPointers)[6])();
funPointer = &fun;
arrayOfFunPointers[0] = funPointer;
pointerToArrayOfFunPointers = &arrayOfFunPointers;
return pointerToArrayOfFunPointers;
}
Outside of the method, the arrayOfFunPointers lose his validity area and the returned pointer point to "nothing"
I tried a lot like:
int (*arrayOfFunPointers[6])() = new int (*[6])();
or with typedef:
typedef int (*arrayOfFunPointers[6])();
arrayOfFunPointerss *array = new arrayOfFunPointers;
or by assignment to the returned pointer:
pointerToArrayOfFunPointers = new arrayOfFunPointers;
pointerToArrayOfFunPointers = new arrayOfFunPointers[]; //or
But nothing works.
Maybe I do not understand the use of the keyword new correctly, then it would be very helpful if anyone could tell me where I make a thinking mistake
Can anyone help me please? That would be nice
(*((*ptr)[i]))();, so why bother? Go with YSC's simplification instead.