title: Non static members as default parameters in C++
body: <p>I'm refactoring a large amount of code where I have to add an extra parameter to a number of functions, which will always have a value of a member of that object.  Something like</p>
  
  <pre><code>class MyClass
  {
  public:
     CMyObject A,B;
  
     void MyFunc(CMyObject &amp;Object);
     // used to be void MyFunc();
  };
  </code></pre>
  
  <p>Now, I'd actually like it to read</p>
  
  <pre><code>class MyClass
  {
  public:
     CMyObject A,B;
  
     void MyFunc(CMyObject &amp;Object = A);
  };
  </code></pre>
  
  <p>But I'm not allowed to have a default parameter that is a non-static member.  I've read <a href="https://stackoverflow.com/questions/2124921/static-binding-of-default-parameter">this similar question</a> which suggest this isn't possible, but I'm wondering if there is any reasonable workaround.  Reason being that 95% of the time the default parameter will be used, and thus using a default parameter would hugely reduce the amount of code I have to change.  My best solution so far is something like this;</p>
  
  <pre><code>class MyClass
  {
  public:
     CMyObject A,B;
  
     void MyFunc(BOOL IsA = TRUE);
  };
  
  void MyClass::MyFunc(BOOL IsA)
  {
      CMyObject &amp;Object = A;
      if (!IsA)
          Object = &amp;B;
  }
  </code></pre>
  
  <p>This is less than elgant, but is there a better way of doing this that I'm missing?</p>
  
  <p><strong>Edit:</strong> FWIW, the reason for the extra parameter is to externalize some state related members from the object in question to aid multi-threading.</p>