title: How to use a member variable as a default argument in C++?
body: <p>I want to make an argument for one of the member functions optional. When no argument is provided, it would use an member variable.</p>
  <p>However, when I tried to compile it it shows</p>
  <pre><code>error: invalid use of non-static data member 'Object::initPos'
  </code></pre>
  <p>Just to isolate the problem, I tried defaulting an int type and it compiled fine.
  I wonder what is the problem with my code and how I could use a member function as default value.</p>
  <p>Thank you for your help!</p>
  <p>Object.h</p>
  <pre><code>class Object
  {
      public:
         ...
         void MoveTo(double speed, Point position);
  
      protected:
         Point initPos; 
         Point currPos;
  
  };
  </code></pre>
  <p>Object.c</p>
  <pre><code>void Object::MoveTo(double speed, Point position = initPos)
  {
      currPos = postion;
  }
  </code></pre>
  <p>Point.h</p>
  <pre><code>class Point
  {
      ...
  
      private:
         double x;
         double y;
         double z; 
  };
  </code></pre>