title: How do I pass an instance member function as callback to std::thread
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/10673585/start-thread-with-member-function">Start thread with member function</a>  </p>
  </blockquote>
  
  
  
  <p>I'm VERY new to C++. My experience has mostly been with javascript and java.</p>
  
  <p>I'm using Xcode on Lion. The following code gives me a compilation error "Reference to non-static member function must be called; did you mean to call it with no arguments?"</p>
  
  <pre><code>class MyClass {
  private:
      void handler() {
      }
  
  public:
      void handleThings() {
          std::thread myThread(handler);
      }
  };
  </code></pre>
  
  <p>I also tried <code>this-&gt;handler</code>, <code>&amp;handler</code>, and other variations, but none of them worked. This code compiles though and accomplishes what I want it to:</p>
  
  <pre><code>class MyClass {
  private:
      void handler() {
      }
  
  public:
      void handleThings() {
          std::thread myThread([this]() {
              handler();
          });
      }
  };
  </code></pre>
  
  <p>Why can't I pass a reference to a member function? Is my work-around the best solution?</p>