There are lots of features
int func001(); int func002(); ... int func015(); ... int func123();
How can all of them go through in a loop?
How to call a function knowing its number?
PS Removed not working code.
There are lots of features
int func001(); int func002(); ... int func015(); ... int func123();
How can all of them go through in a loop?
How to call a function knowing its number?
PS Removed not working code.
@VladD , comments again ended, the previous one being deleted (well, that was copied), but the new one does not allow to create. I had to fill in the answer ...
It definitely needs to be solved by creating a shared library (.so or .dll in Windows).
Do this library. main, when launched, loads it and calls functions by name, depending on the task number.
-
Of course, you can generate the main source from the template every time.
But, IMHO with a loadable library (or several) and a configuration file for them describing the result arguments (assuming some development of the problem) is simply more beautiful.
Create an array of pointers to your functions, and call functions when you walk through the array.
But frankly, a very, very odd task for C ++.
UPD
Another option: write a Perl script that generates a large source file with a call to all these functions.
Something like this.
#include <map> void func1(); void func2(); int main() { std::map<int, func_t> funcs; funcs.insert(std::make_pair(1, &func1)); funcs.insert(std::make_pair(2, &func2)); for(std::map<int, func_t>::iterator i = funcs.begin(); i != funcs.end(); i++) { { i->second(/*аргументы*/); } }
Source: https://ru.stackoverflow.com/questions/229977/
All Articles
FUNC(i)
it wouldfunci()
. - fori1tonstatic
, but the executable module is not "striped." You can analyze your symbol table (in fact,popen(av[0], "r")
outputpopen(av[0], "r")
) and call it when a suitable name is encountered. - avp