title: C++ function pointer to member function
body: <p>I have a worker class, which takes a callback function pointer initialization in the constructor. I would like to instantiate the worker in my class, and provide a pointer to a member function as a callback.</p>
  <p>The worker class:</p>
  <pre><code>class Worker
  {
  public:
      typedef int (*callFunct)(int);
      Worker(callFunct callback = nullptr);
      ~Worker();
  
  private:
      callFunct m_callback = nullptr;
  };
  
  Worker::Worker(callFunct callback) : m_callback(callback)
  {
  }
  </code></pre>
  <p>and here is my class, where I would like to have <code>Worker</code> instance and a member callback function:</p>
  <pre><code>class myClass
  {
  public:
      myClass();
      ~myClass() = default;
  
  private:
      int myCallback(int x);
      Worker m_worker {&amp;myClass::myCallback};
  };
  </code></pre>
  <p>Unfortunately this does not compile:</p>
  <pre><code>    error: could not convert '{&amp;myClass::myCallback}' from '&lt;brace-enclosed initializer list&gt;' to 'Worker'
  </code></pre>
  <p>I am aware that when dealing with pointer to a member class I have to provide the instance object as well. But what is the correct way to do in this situation, when I need to have pointer to class member?</p>