title: C++ Delegate with binding
body: <p>I have to write a delegate in C++ (no C++11 features are allowed) that basically has the two methods <code>Bind()</code> and <code>Invoke()</code>. It should be possible to bind free functions, member functions of any class and const member functions of any class. <code>Bind()</code> stores the function pointer and <code>Invoke()</code> calls the function pointer that was last bound.</p>
  
  <p>I was given example code, which should compile the way given:</p>
  
  <pre><code>void Function(float, double);
  
  Delegate d;
  d.Bind(&amp;Function);
  d.Invoke(1.0, 10);
  </code></pre>
  
  <p>As far this is not a problem. </p>
  
  <pre><code>class Temp
  {
  public:
      void DoSomething(float, double);
  };
  
  Delegate d;
  Temp t;
  d.Bind(&amp;Temp::DoSomething, &amp;t);
  d.Invoke(2.0, 20);
  </code></pre>
  
  <p>Now here is my problem. I wanted to solve this with templates and I am pretty sure that is the way to go. So then I would define something like this:</p>
  
  <pre><code>template&lt;class T&gt;
  class Delegate
  {
  public:
      //here are all the overloads, that is not the difficulty
  private:
      void (*FunctionPointer)(int, float);
      void (T::*memberFunctionPointer)(int, float); //this is my problem
  }
  </code></pre>
  
  <p>But if I define my class this way I cannot instantiate a delegate by just writing</p>
  
  <pre><code>Delegate d;
  </code></pre>
  
  <p>I first receive the type for the <code>memberFunctionPointer</code>, when <code>Bind()</code> is called on delegate.</p>
  
  <p>So, is there a way to do this?<br>
  I have already looked at this post <a href="https://stackoverflow.com/a/9568485/3827069">https://stackoverflow.com/a/9568485/3827069</a> but I was not able to come up with a solution by myself.</p>