#include typedef const char EventArgs; class EventCallback { public: virtual ~EventCallback () {} virtual bool operator () (EventArgs *evargs) = 0; }; class EventMethodCallback : public EventCallback { bool (*callback) (void *self, EventArgs *evargs); void *self; public: template EventMethodCallback (bool (T::*f) (EventArgs *), T *_self) { callback = (bool (*) (void *, EventArgs *)) *((void **)&f); self = _self; } virtual bool operator () (EventArgs *evargs) { return callback (self, evargs); } }; void invoke_event (EventCallback *ec) { bool rc = (*ec) ("abcdef"); printf ("rc = %d\n", rc); } // test class class X { int a, b; public: X () { a = 123; b = 456; } bool callback (EventArgs *evargs) { printf ("Callback: a=%d b=%d args=%s\n", a, b, evargs); return true; } } x; int main () { EventCallback *ec = new EventMethodCallback (&X::callback, &x); invoke_event (ec); delete ec; return 0; } /* Results: [3|zap@zap|~/eeeeeeee]./test Callback: a=123 b=456 args=abcdef rc = 1 */