title: How to run a non-static function in a new thread in C++
body: <p>I am trying to code a basic game in C++. I have a class called player with a function called <em>moveLeft();</em> which constantly monitors the "a" get that I want to run in a separate thread.</p>
  
  <p>Calling it how I thought I was supposed to. I now understand that this is because it's a non-static function, but I'm unsure of how to do this now. I am using the &lt;thread> library.</p>
  
  <h3>Player class</h3>
  
  <pre><code>#pragma once
  class player
  {
      public:
          player(); // Constructor
          ~player(); // Destructor
  
          void moveLeft();
          void moveRight();
          void jump(double);
  
          int getHealth();
  
          double get_x_position();
          double get_y_position();
  
          double get_x_momentum();
          double get_y_momentum();
  
          bool getGrounded();
  
          void setHealth(int);
  
          void set_x_position(double);
          void set_y_position(double);
  
          void set_x_momentum(double);
          void set_y_momentum(double);
  
          void setGrounded(bool);
  
      private:
          int health;
  
          bool grounded;
  
          double x_position;
          double y_position;
  
          double x_momentum;
          double y_momentum;
  };
  </code></pre>
  
  <h3>moveLeft() function</h3>
  
  <pre><code>void player::moveLeft()
  {
      while (true)
      {
          while (GetKeyState(97))
          {
              if (grounded)
              {
                  x_momentum -= .01;
              }
              else
              {
                  x_momentum -= 0.07;
              }
  
              x_position += x_momentum;
          }
      }
  }
  </code></pre>
  
  <p>How I thought I was supposed to set it up.</p>
  
  <pre><code>thread t1(&amp;player::moveLeft);
  t1.detach();
  </code></pre>