   [C++] Simple callback
  Hi,I'm creating a GUI for my game and I'm in a need of a simple callback system.I don't know how to implement it myself, so I came here for help.It would be nice if I could use it like this:myGuiWidget->setCallback(app->changeState(MenuState::getInstance());..void GuiWidget::onClick() {    //This would call the given function    invokeCallback();}Is this even possible? If not, then I would be happy to hear some alternatives.Best regards,zEeLi   
  You might want to look at  Boost.Signals.   ;  What you're looking for is a 'functor' - basically a pair made up of an object upon which a method is called and said method pointer. You could roll your own, but it would be simpler to use the one in boost. If you're doing a GUI you'll discover that for events you usually want more than one callback, so you can go with SiCrane's suggestion (which probably wraps the functor I linked).A simple implementation is to use an interface: IEventHandler which has a 'Execute' method. You then subclass and implement this interface with something useful for you and you pass an instance to the setCallback method. The 'CustomEventHandler' constructor will probably take a pointer to the object whose method you want to call, so it's pretty much the same thing as a 'functor' but you're not using operator() but a specific method.   ;  Thank you both! I'll look into boost.signals first.Best regards,zEeLi   