title: How to delete raw pointers from a unique_ptr
body: <p>I'm writing a game framework, I have a <code>vector&lt;unique_ptr&lt;Object&gt;&gt;</code> list and I distribute pointers from that list by calling <code>object.get()</code> and sending that out. Before that I send out references instead of raw pointers but that resulted in other weird problem so I was told this is better. However when I remove a <code>unique_ptr&lt;Object&gt;</code>from the list, the raw pointers remains. I also can't deallocate them manually, I get an exception saying the pointer is not allocated.</p>
  
  <p>So my question would be: </p>
  
  <ol>
  <li>How do I delete raw pointers from removed unique_ptr's? </li>
  </ol>
  
  <p>and is also a more general question: </p>
  
  <ol start="2">
  <li>Am I on the right track structure wise of passing pointers instead of references?</li>
  </ol>
  
  
  
  <pre><code>PxlObject* PxlFramework::AddObject(PxlObject* obj)
  {
      std::unique_ptr&lt;PxlObject&gt; u_ptr(obj);
      objects_iterator = objects.insert(objects.end(), std::move(u_ptr));
      return obj;
  }
  
  void PxlFramework::DeleteObject(PxlObject* obj) {
      for(objects_iterator = objects.begin(); objects_iterator != objects.end(); ++objects_iterator)
      {
          if((*objects_iterator)-&gt;get_id() == obj-&gt;get_id())
          {
              //attempting to delete the raw pointer here but it will result in an error
              delete obj;
  
              //removing the unique_ptr&lt;PxlObject&gt; from the list here
              std::swap((*objects_iterator), objects.back());
              objects.pop_back();
              break;
          }
      }
  }
  </code></pre>