Probably more C than C++, but I'm using Borland Builder (v3), so I have that available to me.
Iím writing an application that reads a script file. The script file might look something like this.
It just breaks down as a ď~Ē delimited file. LineNumber~function~parameters.
Now, I can parse it out just fine and get the line numbers into int variables and the functions into char* or AnsiString or whatever variables and get the parameters parsed out ok. What I need to do now is call the functions by those names.
i.e. I have functions
int add(int x, int y)
int subtract(int x, int y)
int multiply(int x, int y)
GetScriptLine(function, &x, &y);
// function now contains the char array ďaddĒ and x==1 and y==2
// can I call a function something like this
Execute(function, x, y);
/*where Execute() runs the add function in this case and the subtract function on the next script line and multiplyÖ without a big switch statement or a group of if's? Iíve been reading up on pointers to functions, but I havenít found any examples of
Of course the program is not quite as simple as common math functions, and will have many functions to call (that's why I don't want to use if's) but if I can accomplish this, the translation will be a snap. Any Ideas?
It's not a problem to have to have the parameters all the same either. I have a facility for doing that if I need it. i.e. Execute(function, &DataList); where DataList is simply a list of strings (I'll do the conversion in the add(), subtract(), multiply()... functions because in the real app, the functions will take considerably different arguments.
Happy New Year by the way.
Thanks for any help,