rendered paste body#include <stdio.h>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 <class T> 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 classclass 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]./testCallback: a=123 b=456 args=abcdefrc = 1*/