title: std::thread : how to declare a thread in class body as a normal member?
body: <p>I want to have a thread for each instance of <code>Page</code> object. At a time only one of them can execute (simply checks if pointer to current running thread is joinable or not..)</p>
  
  <pre><code>class Page : public std::vector&lt;Step&gt;
  {
      // ....
      void play();
      void start(); // check if no other thread is running. if there is a running thread, return. else join starter
      std::thread starter; // std::thread running this-&gt;play()
      static std::thread* current; // pointer to current running thread
      // ...
  };
  </code></pre>
  
  <p>I want to be able to fire-up <code>starter</code> threads of <code>Page</code> objects. for example like this:</p>
  
  <pre><code>Page x , y , z;
  // do some stuff for initialize pages..
  x.start();
  // do some other work
  y.start(); // if x is finished, start y otherwise do nothing
  // do some other lengthy work
  z.start(); // if x and y are not running, start z
  </code></pre>
  
  <p>I can't manage to declare <code>started</code> as a member of <code>Page</code>. I found that it's because of the fact <code>std::thread</code>s can only initialized at declaration time. (or something like that, cause it's not possible to copy a thread)</p>
  
  <pre><code>void x()
  {
  }
  //...
  std::thread t(x);          // this is ok
  std::thread r;             // this is wrong, but I need this !
  r = std::thread(this-&gt;y);  // no hope
  r = std::thread(y);        // this is wrong too
  </code></pre>