title: C++ unique_pointer and pointer
body: <p>I tried fiddling around with the unique_ptr. </p>
  
  <p>Why does the line marked with MK1 (comment) not crash my program?</p>
  
  <p>Foo destructor is called. By using unique_ptr I thought both the destructor for the object was called and deleted the memory allocated for the object itself.</p>
  
  <p>I'm guessing its unique, so I shouldnt let others point to the same Foo?</p>
  
  <pre><code>void ExMemory() {
    Foo *simplePtr;
    {
      std::unique_ptr&lt;Foo&gt; p1(new Foo);
      simplePtr = &amp;*p1; // Does unique_ptr increment a reference counter?
      p1-&gt;bar();
      simplePtr-&gt;bar();
    }
    simplePtr-&gt;bar(); // MK1: Why can I do this? Foo destructor is called.
    delete simplePtr;
    simplePtr-&gt;bar(); // Causes the error I expected earlier.
  }
  
  int main() {
    cout &lt;&lt; "Hello main" &lt;&lt; endl;
    ExMemory();
    int x;
    cin &gt;&gt; x;
    return 0;
  }
  </code></pre>