title: Passing mutex reference from main to a class
body: <p>I need to work with the same <code>mutex</code> and <code>unique_lock</code> across the main function and class instances. However, I am having trouble assigning the <code>mutex</code>/<code>unique_lock</code> address to a class member variable (that is a <code>mutex&amp;</code>).</p>
  
  <p>This is what I have:</p>
  
  <p><strong>Worker.h</strong></p>
  
  <pre><code>class Worker 
  {
  private:
  
      std::mutex &amp;m_mu;
      std::unique_lock&lt;std::mutex&gt; &amp;locker;
  
  public:
  
      void start(std::mutex &amp;mu, std::unique_lock&lt;std::mutex&gt; &amp;locker);
  
  };
  </code></pre>
  
  <p><strong>Worker.cpp</strong></p>
  
  <pre><code>void Worker::start(std::mutex &amp;mu, std::unique_lock&lt;std::mutex&gt; &amp;locker)
  {
      this-&gt;mu = mu; // error 
      this-&gt;locker = locker; // error
  }
  </code></pre>
  
  <p>I tried doing <code>this-&gt;mu(mu)</code>; but that doesn't work either. Is there anything I can do to make this work?</p>
  
  <p>Thanks.</p>