Function Pointers... Benefits?

I am constantly looking back through my code and trying to find better ways of doing things. I am again looking at Function Pointers... I don't see/understand their value and they seem completely unnecessary. Can anyone "enlighten" me?

Thanks,
Return 0;
I think this is probably the most common use for function pointers:
1
2
3
4
5
6
7
std::map<std::string,void(*)(const Data &)> commands;
commands["cp"]=&cpF;
commands["cd"]=&cdF;
commands["mv"]=&mvF;
commands["rm"]=&rmF;
//get user input
(*commands[input])(data); //(can't remember ATM if the dereference was necessary) 
Jump-table style lookup (like helios's example), and callbacks are the two most common. Callbacks can be handy for inter-thread communication, or for a way to abstract something in a more submissive way. IE, you can use a function pointer to call something in class A without having to be aware of class A's existance (or any of its parents).
They can be also used to attach a function to a task defined by a library as OpenGL does
That makes a little more sense. Thanks.
Topic archived. No new replies allowed.