Advertisement

How do I use function pointers?

Started by April 12, 2001 05:30 PM
3 comments, last by Kranomano 23 years, 10 months ago
I want to make a scripting engine, with a function that associates a string with a function, so when the parser comes accross that string, it executes the function that is associated with it in a table. I know this can be done with function pointers, but... what are function pointers? It would be a great help if someone would give me some code or a link. Thanks.
  // Here''s my example functionbool SomeFunc(int a, int b) {  // Do Something  return false;}// Here''s a function pointerbool (*FuncPointer)(int, int) = SomeFunc;// Now we call it like normal (the following are both the same pretty much)SomeFunc(58,291);FuncPointer(58,291);  


"Finger to spiritual emptiness underlying everything." -- How a C manual referred to a "pointer to void." --Things People Said
Resist Windows XP''s Invasive Production Activation Technology!
http://druidgames.cjb.net/
Advertisement
hm. I thought I tried that... but thanks! thats realllllly cool.
Just as an added thought ... you may want to typedef your function pointer. It will make your life a little easier, especially if you ever have the requirement to typecast.

--


Get a stripper on your desktop!

You might want to use a std::map<> structure to map out your functions for your scripting thing...

ie

  std::map<std::string,bool (*pFunc)(int&, int& )> FunctionMap;  


Just a hint

regards,
ecko_53

-----------------------------------------------------------
"If I wanted to hear the pitter patter of little feet I would put shoes on my cat"
-----------------------------------------------------------"People who usualy use the word pedantic usualy are pedantic!"-me

This topic is closed to new replies.

Advertisement