title: How to cast vector<T>::iterator (on the heap) as shared_ptr<T>
body: <p><em>I'm afraid that each existing question/answer in this area seems to be subtly different:</em></p>
  
  <p>I have a <strong><code>shared_ptr&lt;vector&lt;Point&gt;&gt; profile</code></strong> which is looped using an iterator. I would like to preserve a <strong><code>shared_ptr&lt;Point&gt;</code></strong> outside the loop for various purposes, but am struggling with the syntax. Please can you advise?</p>
  
  <p>Here is a basic example:</p>
  
  <pre><code>shared_ptr&lt;Point&gt; peak;
  for (vector&lt;Point&gt;::iterator point=profile-&gt;begin(); point!=profile-&gt;end(); point++)
  {
      ...
      peak = shared_ptr&lt;Point&gt;(*point); // fails
      ...
  }
  </code></pre>
  
  <p><em>N.B. I suppose that using a plain reference/pointer to the <code>Point</code> would be simple enough, but I am trying to avoid this, particularly when the heap is involved. I also realise that I could use indexes in this case, but this would be less transferable between container classes.</em></p>