title: Using std::thread outside main source file in c++
body: <p>I'm trying to use thread but it doesn't work outside main source file.
  For example it doesn't work</p>
  <pre><code>void Game::foo() {
      std::cout &lt;&lt; &quot;Why are you not working properly&quot;;
  }
  
  void Game::threadStart() {
      std::thread th(foo); //here is something wrong
  }
  </code></pre>
  <p>But this works(it is in main source file)</p>
  <pre><code>void foo() {
      std::cout &lt;&lt; &quot;I'm working properly&quot;;
  }
  
  void thread() {
      std::thread th(foo);
  }
  </code></pre>
  <p>What more, when in 2nd option in main file when i want to use pointer on function it doesn't work.</p>
  <pre><code>Resource* res = new Resource();
  Pocket* pock = new Pocket();
  
  void thread() {
      std::thread th(res-&gt;product,pock); // pock is an arg of function product();
  }
  </code></pre>
  <p>Any suggestion how to fix it. In the second code I could send pointers as parms and then use</p>
  <pre><code>res-&gt;product(pock)
  </code></pre>
  <p>but I think using to functions two use 1 thread witch use another function is stupid.</p>