title: c++ default parameters
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/4539406/nonstatic-member-as-a-default-argument-of-a-nonstatic-member-function">Nonstatic member as a default argument of a nonstatic member function</a>  </p>
  </blockquote>
  
  
  
  <p>Ok. So I'm having problems understanding how to accomplish a seemingly simple task... Here is what I want to accomplish:</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  using namespace std;
  
  class A{
  private:
      int _x;
  public:
      A(int x){
          _x = x;
      }
  
      void test(int x=_x){
          cout &lt;&lt; x &lt;&lt; endl;
      }
  };
  
  int main(){
      A a(3);
      a.test();
  }
  </code></pre>
  
  <p>The compiler complains about the <code>int x=_x</code> part saying <code>error: invalid use of non-static data member A::_x</code></p>
  
  <p>So how do I use a default parameter like this?</p>
  
  <p>Thanks.</p>