Random code snippet

//
// Event handler for a callback that takes no parameters
//
class EventHandlerBase
{
   virtual void HandleEvent() = 0;
};

//
// T is the class that will receive callbacks
// U is the method signature or something
//
template <class T, class U >
class EventHandler
{
   T _obj;
   U _func;

public:
   EventHandler( T * obj, U * func )
      : _obj( obj ),
        _func( func )
   {
      ;
   }

   void Register( T * obj, U * func )
   {
      _obj = obj;               // param checking?
      _func = func;
   }

   void HandleEvent()
   {
      _func->obj();
   }
};

Leave a Reply

You must be logged in to post a comment.