title: boost::bind & boost::function pointers to overloaded or templated member functions
body: <p>I have a callback mechanism, the classes involved are:</p>
  
  <pre><code>class App
  {
      void onEvent(const MyEvent&amp; event);
      void onEvent(const MyOtherEvent&amp; event);
  
      Connector connect;
  }
  
  class Connector
  {  
     template &lt;class T&gt; void Subscribe(boost::function &lt;void (const T&amp;)&gt; callback);
  }
  
  App::App()
  {
      connect.Subscribe&lt;MyEvent&gt;(&amp;App::OnEvent&lt;MyEvent&gt;);
  }
  </code></pre>
  
  <p>First off this code doesn't compile, it's an illustration. </p>
  
  <p>The use of templates complicates my example, but I left them in because its affecting my problem. It seems certain to me that my subscribe needs to be templated because the Connector class doesn't know how many event types it handles. When I try to create a:</p>
  
  <pre><code>boost::function f = &amp;App::OnEvent, 
  </code></pre>
  
  <p>I tried creating OnEvent as a template function, with specializations, but it seems that the compiler is treating my OnEvent functions as overloads rather than template specializations, or else I get the template specialization not in namespace error if I try to explicitly declare it as </p>
  
  <pre><code>template &lt;&gt; OnEvent(const MyEvent&amp; e) ...
  </code></pre>
  
  <p>I can get the following to compile:</p>
  
  <pre><code>boost::function &lt;void (App*, const MyEvent&amp;)&gt; f = &amp;App::OnEvent;
  f(this, e); 
  </code></pre>
  
  <p>That compiles, runs, and works.</p>
  
  <pre><code>boost::function&lt;void (const MyEvent&amp;)&gt; g = boost::bind(&amp;App::OnEvent, this);
  </code></pre>
  
  <p>does not. I think its because I'm not correctly specifying the address of an overloaded function. </p>
  
  <p>Having now explained all this to the teddy bear - I think that my question is "How do I correctly create a function pointer to an overloaded or templated member function and bind the this pointer to it?" </p>