title: Guarded thread C++
body: <p>I'm trying to create a &quot;guarded_thread&quot;, but I receive an error 'operator=' is a private member of 'std::__1::thread'. Here is my code:</p>
  <pre><code>struct guarded_thread : std::thread{
      using std::thread::thread;
      using std::thread::operator=;
      ~guarded_thread(){if(joinable())join();}
  };
  </code></pre>
  <p>A function did the work, but I want to know how to create it the other way</p>
  <pre><code>void Guarded_thread(std::thread &amp;Thread){
      if (Thread.joinable()) {
          Thread.join();
      }
  }
  </code></pre>