If I were you, I would not use function pointers to accomplish this task. Leave this opportunity to the guru;)
Boost has a beautiful library called signals . It makes your life easier! This is a usage example:
#include <iostream>
This will print:
Hello I am X! A::A_action(); B::B_action(); C::C_action();
Here's how it works.
First you declare the place where delegates are stored:
signal<void()> list_of_actions;
Then you βconnectβ it to any group of functions / functions / called things that you want to call.
x.list_of_actions.connect(bind(&A::A_action, a)); x.list_of_actions.connect(bind(&B::B_action, b)); x.list_of_actions.connect(bind(&C::C_action, c));
Please note that I used bind . So, the type of functions in list_of_actions is the same, but we can connect it to different types of classes. So:
bind(&A::A_action, a)
This thing creates a calling thing like void () , as we previously declared a list_of actions type. Of course, you specify the instance that you want to apply this member function in the second parameter.
If you are doing multithreaded things, use his sister signals2 .
Hope this helps.
Arak
source share