title: Thread creation inside constructor
body: <p>So, I am using C++11 and I made a class</p>
  
  <pre class="lang-cpp prettyprint-override"><code>Class C
  {
    private:
      queue&lt;std::int&gt; s;
      pthread_t x;
    public:
      C() {phthread_create(&amp;x, NULL, d_q, NULL);
      void log(int p); // pushes into q.
      void* d_q(void* q); // this is a function which will pop s. assume s is thread safe.
  }
  </code></pre>
  
  <p>The problem is the line <code>pthread_create(&amp;x, NULL, d_q, NULL)</code>. It gives me <code>Error: Reference to non-static member must be called.</code></p>
  
  <p>I get rid of this problem by making pthread_t x <code>static</code>. But I dont want to do this because of 2 reasons:</p>
  
  <ol>
  <li>Creation of a thread with a static function means only 1 copy of the function.</li>
  <li>The thread is created in a constructor. I don't know what will happen if I create more than one objects of class C.</li>
  </ol>
  
  <p>Can someone please give me a workaround?</p>
  
  <p>Solved: Thanks for the help! 
  Also, a very good advice is to <strong>prefer std::thread over pthread for future users!</strong></p>