I am attempting to make an array of function pointers.
The array is going to be of quite a few functions (between 10 and 50 somewhere).
This declaration is similar to the one I’m using:
int (*functions[15])(int, int);
The issue I am encountering is that I will have to define all of these functions by hand. This is fine; however I do not care to give a name to all of them.
None of the functions that will be in the array will be called from outside of the array.
I know I’m pushing my luck with this question, but is there a way for me to put anonymous functions (similar to delegates, I suppose) into this array?
or could I use a declaration similar to this:
int (*functions[15])(int, int);
(*function[0])(int x, int y)
{
//stuff
}
(*function[1])(int x, int y)
{
//other stuff
}
I hope to avoid using any C++11 with this, as well, if possible; I understand a lot of improvements have been made with it, but I don’t know if all compilers would support it yet (I intend on using multiple compilers across platforms).
Is there a way to do this without naming every single function, or am I out of luck?
Without anonymous functions, you need to name your functions. There’s no alternative in pre C++11.