Hello :)
I was just wondering if it was possible to make an array of functions?
To roughly get an idea, here is some fake code:
In this case the output of the program would beCode:int function[2]; //the array would be called 'function', have 2 slots, with the functions being int types
function[0](x) //the first function would take on the name function[0] and take one argument
{
cout << x << endl;
}
function[1](y) //the second function would have name function[1] and have one arg
{
cout << y*y << endl;
}
int main()
{
function[0](1); //x = 1 as an example
function[1](2); //y = 2 as an example
}
1
4
This is fake code that does not work. I was just curious if there was a way to do such a thing.
The advantage I'm looking for is to have indexed names for functions, which would make them easier to organize.
How is this done in C++?
Thanks everyone :)