I have several overloaded functions in c++ and I would like to make an array of them, so that I can use them in a loop (in fact I want to call them randomly). Could you help ? Tutorials only show how to do arrays of function pointers with identical function arguments.
Share
I think that the main problem here is that it seems that what you want requires the determination of the type and order of the function arguments in execution time and not in compilation time. What is your main goal here? execution speed? code readability or “correctness”? If you go for execution speed, then I think that there is some ugly solution. As far I understand your problem, you will decide which “overloaded function” you will call using a random choice of the index of the array. So one not necessarily safe possibility is to use functors and pass to the creator of each functor in the array pointers to the variables it will use in the future as if those variables are its arguments. But this works only if you allways will use the same variables as the arguments of the “function” calls.