title: Creating a class member pointer function variable that points to a non-static class member function
body: <p>The goal is to have the member variable <code>_AddValue</code> point to the <code>CreateFirstValue</code> function upon class initialization and after the first invocation of <code>AddValue</code>, all future calls to it will invoke <code>CreateAnotherValue</code>.</p>
  
  <p>Previously, I just had a single <code>AddValue</code> function with a conditional check to determine which function to call. However, I feel like that implementation is flawed because that <code>if</code> check will occur every time and it seems like a function pointer would be beneficial here.</p>
  
  <p>An example:</p>
  
  <pre><code>class Foo
  {
   private:
    int _value;
    void (*_AddValue)(int value); // Pointer to function member variable
  
    void CreateFirstValue(int value)
    {
      _value = value;
      _AddValue = &amp;CreateAnotherValue;
    }
  
    void CreateAnotherValue(int value)
    {
      // This function will create values differently.
      _value = ...;
    }
  
   public:
    // Constructor
    Foo()
     : _value(0), _AddValue(CreateFirstValue)
    {
    }
  
    AddValue(int value) // This function is called by the user.
    {
      _AddValue(value);
    }
  };
  </code></pre>
  
  <p>The code above is not the actual code, just an example of what I'm trying to accomplish.</p>
  
  <p>right now I'm getting an error: <code>argument of type void (BTree::)(int) does not match void (*)(int)</code></p>