title: Storing an std::thread object as a class member
body: <p>I'm trying to keep an <code>std::thread</code> object inside a class.</p>
  
  <pre><code>class GenericWindow
  {
      public:
          void Create()
          {
              // ...
              MessageLoopThread = std::thread(&amp;GenericWindow::MessageLoop, *this);
          }
      private:
          std::thread MessageLoopThread;
          void GenericWindow::Destroy()   // Called from the destructor
          {
              SendMessageW(m_hWnd, WM_DESTROY, NULL, NULL);
              UnregisterClassW(m_ClassName.c_str(), m_WindowClass.hInstance);
              MessageLoopThread.join();
          } 
          void GenericWindow::MessageLoop()
          {
              MSG Msg;
              while (GetMessageW(&amp;Msg, NULL, 0, 0))
              {
                  if (!IsDialogMessageW(m_hWnd, &amp;Msg))
                  {
                      TranslateMessage(&amp;Msg);
                      DispatchMessageW(&amp;Msg);
                  }
              }
          }
  };      // LINE 66
  </code></pre>
  
  <p>Error given:</p>
  
  <pre>[Line 66] Error C2248: 'std::thread::thread' : cannot access private member declared in class 'std::thread'</pre>
  
  <p>This error message doesn't help me, I'm not trying to access any private member of the <code>std::thread</code> class.</p>
  
  <p>What is wrong in my code? How do I fix it?</p>