Well, I've been called worse.
I guess I'd just like to hear some more detail about your problem and why this was chosen as a solution. I'm afraid we might be standing around discussing which hammer is the best choice for pounding in screws.
At this point, it appears that the hammer almost works, so if you can bear with me for a few iterations, I would appreciate it.
I have solved the std::map problem by adding a #include <map>.
So I try the code:
Defining the function pointer survives the compiler.Code:
//define a function pointer
typedef double (*fnc_ptr)(double x);
//this will be your function registry
std::map<std::string, fnc_ptr> fncRegistry;
//maybe this is not actually needed [I try with and without this line, of course]
double MYROUTINE_A(double x);
double MYROUTINE_A(double x)
fncRegistry("MYROUTINE_A", MYROUTINE_A); // < this line now has the error
//define the function
double MYBOSSESROUTINE(const char* z)
fncRegistry(z)(10.2); //call z
Establishing the map, aka function registry survives the compiler.
When I add the line above the comment indicating that further code defines the function, the compiler complains with:
error C2064: term does not evaluate to a function taking 2 arguments.
I must admit, putting the line "fncRegistry("MYROUTINE_A", MYROUTINE_A)" *inside* the definition of the function itself puzzles me. If the purpose is to add the information to the registry, one would think you would do it once, not every time the function is called.
In any event, that is where I'm stuck right now. I will continue to massage what I can and ask that if anybody spots the specific issue to please let me know.
brewbuck, I appreciate your point of view, but there are very good reasons (well beyond this one project) where the name of the function [or a portion of the name of the function] will be defined in such a way as to make it subject to input from higher up the food chain (including all the way to the user), so consider this a prototype. Many text based languages have this construct built in. I'm not complaining about the fact that it isn't built-in here, just trying to re-create the capability.
fncRegistry.insert( std::make_pair("MYROUTINE_A", MYROUTINE_A) );
And should be done ONLY once. Ie, put it somewhere in your initialization code.
It looks like someone was half-sleeping when that code was written.
Thanks. I thought that line was misplaced and questioned its efficacy.
I'll try your suggestion as soon as I re-install VS2008. I'm embarrassed to say that I somehow blew it up by merely trying to copy a .cpp file from one project to another. <sigh> But I did want to thank you for the response.
Man that code looks like it's asking for trouble. You should work with your boss to fix it.
Well, trouble is my middle name.
Thanks for sharing.
Adding to the map now works. Thanks for that.
Calling the function still doesn't.
fncRegistry(z)(12.08333); //call z
and various offshoots with the word "call", but the compiler comes back with:
error C2064: term does not evaluate to a function taking 1 arguments
The signature of the function is:
double MYROUTINE_A(double x)
which, of course, is why the compiler wants my call statement to resolve to a call with one parameter.
If anybody can spot the error, that would be appreciated.
Post the smallest and simplest program that demonstrates the problem.
My guess is that you should have written:
And, indeed, you would be right! Thanks!!!!!!!!!!!!!!!!!!!!!!!!
Now we will see if I can tie all this spaghetti together.
Thank you, thank you, thank you for that edit!!!
Edit: And the spaghetti now works. Many thanks, again!!!!!!!!