title: Callback in C++, template member?
body: <p>Following code does NOT work, but it expresses well what I wish to do. There is a problem with the template struct container, which I think SHOULD work because it's size is known for any template argument.</p>
  
  <pre><code>class callback {
  
    public:
  
    // constructs a callback to a method in the context of a given object
    template&lt;class C&gt;
    callback(C&amp; object, void (C::*method)())
      : ptr.o(object), ptr.m(method) {}
  
    // calls the method
    void operator()() {
      (&amp;ptr.o -&gt;* ptr.m) ();
    }
  
    private:
  
    // container for the pointer to method
    template&lt;class C&gt;
    struct {
      C&amp; o;
      void (C::*m)();
    } ptr;
  
  };
  </code></pre>
  
  <p>Is there any way to do such a thing? I mean have a non-template class callback which wraps any pointer to method?</p>
  
  <p>Thanks C++ gurus!</p>
  
  <p><strong>Edit:</strong></p>
  
  <p>Please see this:</p>
  
  <p><a href="https://stackoverflow.com/questions/1284239/callback-in-c-template-member-2">Callback in C++, template member? (2)</a></p>