rendered paste body#include <stdio.h>template<class T>class Delegate{ typedef void (T::*Method)(void); T * obj_ptr; Method func_ptr;public: Delegate() { ; } Delegate(T * obj) { obj_ptr = obj; } Delegate(const Delegate<T> &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<Base> * d; B(void) { d = new Delegate<Base>(); }};class A : Base{ B * b;public: A(void) { b = new B(); b->d = new Delegate<A>(this); } void foo(void) { printf("Hello, world!\n"); }};int main (int argc, char * const argv[]) { A * a; Delegate<A> * d = new Delegate<A>(a); d->AddMethod(&A::foo); d->Invoke(); return 0;}