#include template class Delegate { typedef void (T::*Method)(void); T * obj_ptr; Method func_ptr; public: Delegate() { ; } Delegate(T * obj) { obj_ptr = obj; } Delegate(const Delegate &other) { this->obj_ptr = other->obj_ptr; this->func_ptr = other->func_ptr; } void AddMethod(Method func) { func_ptr = func; } void Invoke(void) { (obj_ptr->*func_ptr)(); } }; class Base { ; }; class B : Base { public: Delegate * d; B(void) { d = new Delegate(); } }; class A : Base { B * b; public: A(void) { b = new B(); b->d = new Delegate(this); } void foo(void) { printf("Hello, world!\n"); } }; int main (int argc, char * const argv[]) { A * a; Delegate * d = new Delegate(a); d->AddMethod(&A::foo); d->Invoke(); return 0; }