title: How to assign the address of an existing object to a smart pointer?
body: <pre><code>#include &lt;memory&gt;
  
  class bar{};
  
  void foo(bar &amp;object){
      std::unique_ptr&lt;bar&gt; pointer = &amp;object;
  }
  </code></pre>
  
  <p>I want to assign an address of the object to the pointer. The above code obviously wont compile, because the right side of the assignment operator needs to be a std::unique_ptr. I've already tried this:</p>
  
  <pre><code>pointer = std::make_unique&lt;bar&gt;(object)
  </code></pre>
  
  <p>But it throws many errors during compilation. How can I do that?</p>
  
  <p><strong>Update</strong><br>
  As said in the answers - using the <code>std::unique_ptr::reset</code> method led to undefined behaviour. Now I know, that in such cases I should use a standard pointer.</p>