Since in this case, the array decays into a pointer, you don't have to know its size beforehand -- inside a function argument declaration, and only there, the pointer and the array qualifier (*
and []
) are equivalent, and the size of the array doesn't matter.
As a result, you can declare your function to take an array of 3 (or however many) pointers, and then you can pass it an array of any pointers:
void callFunctionsFromAnArray(void *(*f[1])(int), int fCount)
{
for (int i = 0; i < fCount; i++)
f[i](i);
}
However, if you don't like this, you can just make it accept a pointer-to-pointer:
void callFunctionsFromAnArray(void *(**f)(int), int fCount); // etc.
However, if this really is C++, you'd be better off passing a const reference to a vector of std::function
s:
void callFunctionsFromAnArray(const std::vector<std::function<void *(int)> > &a)
{
// call'em
}