title: C++ -- Join a vector of threads
body: <p>I am using g++ 4.8 to write a c++11 program. I'm trying to convert a single threaded program to multi-threaded one. The join in the threaded version ends up throwing a compilation error. Could you please let me know where I'm going wrong?</p>
  
  <p>Single Threaded(works well):
  Note that all arguments are pass by reference.</p>
  
  <pre><code>for (const auto&amp; i : vec_clients)
  {
      i-&gt;startSim(vec_masters, vec_trace1, vec_trace2, vec_trace3);
  }
  </code></pre>
  
  <p>Multi-Threaded version:</p>
  
  <pre><code>std::vector&lt;std::thread&gt; vec_thr;
  for (const auto&amp; i : vec_clients)
  {
      std::thread t1(&amp;Client::startSim, std::move(i), std::move(vec_trace1), std::move(vec_trace2), std::move(vec_trace3));
      vec_thr.push_back(std::move(t1));
  }
  for (unsigned int i=0; i&lt;vec_thr.size(); ++i)
  {
      // if (i.joinable())
          vec_thr.at(i).join();
  }
  </code></pre>
  
  <p>Modified(simpler example):</p>
  
  <pre><code>class Test
  {
  private:
  public:
      void testme(const std::string&amp; _str)
      {
          std::cout &lt;&lt; "Hello "+_str &lt;&lt; std::endl;
      }
  };
  
  int main(const int argc, const char **argv)
  {
      std::string str = "there";
      Test t1;
      std::vector&lt;std::thread&gt; vec_thr;
  std::thread thr1(&amp;Test::testme, std::move(t1), std::cref(str));
      vec_thr.push_back(thr1);
      return 0;
  }
  </code></pre>