I want to call C++ functions on this way:
I have an array that matches strings with corresponding c++ function
int x() {
return 6;
}
int y(int t){
return t;
}
A functions[] = { { "x" , void*&x } , { "y", void*&y}};
A is as simple struct. The program gets a string as input of user.
If i have a black-magic box function Z , that takes as parameter a string, and searchs in array "functions" and returns the second element of struct which equals with the string parameter.
For example Z("x")
returns void*&x
..etc..
If i don't know all the functions in functions array how can i call the returned function of Z?
for example i want something like this:
void * g = Z("y"); //returns the y function
g(8);
I don't want a specific cast or if/else, because for the first the first time the user maybe give "x" and the seconde time give "y", and for the second I don't want if/else cases because the number of function may be infinity.