title: On the use (and usefulness) of a pointer to member function vs directly calling the member function
body: <p>I am new to pointer to member functions, and I would like to know their pros and cons.</p>
  
  <p>Specifically, consider this:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;list&gt;
  
  using namespace std;
  
  class VariableContainer;
  
  class Variable
  {
  public:
    Variable (int v) : value (v), cb_pointer (0) {}
    ~Variable () {}
  
    void SetCallback (void (VariableContainer::*cb)(int)) {
      cb_pointer = cb;
    }
    void FireCallback (void) {
      /* I need a reference to a VariableContainer object! */
    }
  
  private:
    int value;
    void (VariableContainer::*cb_pointer) (int);
  };
  
  class VariableContainer
  {
  public:
    VariableContainer () {}
    ~VariableContainer () {}
  
    void AddVar (Variable &amp;v) {
      v.SetCallback (&amp;VariableContainer::Callback);
    }
    void Callback (int v) { cout &lt;&lt; v &lt;&lt; endl; }
  };
  
  int main ()
  {
    Variable v (1);
    VariableContainer vc;
  
    vc.AddVar (v);
    v.FireCallback();
  
    return 0;
  }
  </code></pre>
  
  <p>As stated in the comment, to trigger the callback (<code>FireCallback</code>) I need some reference to an existing <code>VariableContainer</code> object, which should be provided as an additional argument of <code>VariableContainer::AddVar (...)</code>.
  Now:</p>
  
  <ol>
  <li>Should I use the pointer to member function? Or should I call directly <code>Callback (...)</code> (since I have a pointer to the <code>VariableContainer</code> object)?</li>
  <li>What are the advantages and drawbacks of each solution?</li>
  </ol>
  
  <p>TIA,
  Jir</p>