okeydokey, time for another of my weird hypothetical example spawned questions. If i have a pile of functions, func1, someotherfunc, ... morefuncsthanicancount. that all do different things. and i got my luser...erm... user who enters the name of a function, how do i go about calling what they enter. if they type in func42 i want it to call func42. now my thought on how to do this was a vector of pair<string,function*> so i could search the vector for the right string, and execute the function pointer by address rather than name. now for some problems. how do i pass parameters to these? if they enter func32 X Y how can i pass the X and Y being that i dont know the prototype of functions i will be calling. again my bad idea was to have every function take a void pointer and type cast it over to whatever struct of parameters that particular function wanted. Before i waste the next 90 hours of my life trying to code this thing, i want to know what i have stated that clearly wont work, or is terribly flawed, or will make me just scrap the whole project, and how to get the address of a function to store to a vector. thanks for feeding my imagination.
I can't see why you would want the user just to enter something like 'func42' or whatever...Um why do you want to do this? Can you think of one useful program that does (would do this)? Ok sorry...Just wondering...Maybe I missed your point
it would be for use in my new toy. im trying to provide a user with a scripted config file. they could script addons to the program. i could just parse the config file and allow new functions to be added as necessary.
First, I'd use a map<string, function*>... Its an associative container, so you'd simply have (for example):
Second, to have a function pointer, you must know the prototype. void* is one way to pass different things. You could also just pass them the string of parameters, and have them parse that string themselves (a better idea).
map<string, void (*)(void)> func_map;
Especially if this is for scripting.