View Single Post
Old Feb 11th, 2008, 9:38 AM   #15
Game_Ender
Professional Programmer
 
Game_Ender's Avatar
 
Join Date: May 2006
Location: Maryland, USA
Posts: 306
Rep Power: 3 Game_Ender is on a distinguished road
Re: Pointer to member function

This is also possible with Boost.Bind + Boost.Function. Example:
cpp Syntax (Toggle Plain Text)
  1. class button
  2. {
  3. public:
  4.  
  5. boost::function<void> onClick;
  6. };
  7.  
  8. class player
  9. {
  10. public:
  11.  
  12. void play();
  13. void stop();
  14. };
  15.  
  16. button playButton, stopButton;
  17. player thePlayer;
  18.  
  19. void connect()
  20. {
  21. playButton.onClick = boost::bind(&player::play, &thePlayer);
  22. stopButton.onClick = boost::bind(&player::stop, &thePlayer);
  23.  
  24. // Calls player::play() on thePlayer object
  25. playButton.onClick();
  26. }
__________________
Robotics @ Maryland AUV Team - Software Lead
Game_Ender is offline   Reply With Quote