title: shared_ptr from unique_ptr of abstract class
body: <p>I'm trying to follow Herb Sutter's C++ guidelines, in this case to prefer <code>unique_ptr</code> to raw pointers and <code>shared_ptr</code>. One of the arguments in favour of <code>std::unique_ptr</code> is convertibility to <code>shared_ptr</code> should that be needed at some point.</p>
  
  <p>In my case I have a <code>vector</code> of <code>unique_ptr</code> that I need to pass to a method that takes a <code>vector</code> of <code>shared_ptr</code>. I was hoping to be able to write something like:</p>
  
  <pre><code>for (auto &amp;uniquePtr : vectorUnique)
      vectorShared.push_back(make_shared&lt;Abstract&gt;(move(uniquePtr));
  </code></pre>
  
  <p>This gives me the following error with my <code>Xcode 7.1</code> based toolchain configured for <code>C++11</code>:</p>
  
  <blockquote>
    <p>error: field type 'Abstract' is an abstract class.</p>
  </blockquote>
  
  <p>It seems the STL is trying to hold a concrete instance of type <code>Abstract</code> when I use <code>make_shared</code>. That would seem to make Mr. Sutter's advice unworkable in many cases, so I'm sure I must be doing something wrong! I've resorted to writing:</p>
  
  <pre><code>for (auto &amp;uniquePtr : vectorUnique) {
      auto ptr = uniquePtr.get();
      auto shared = shared_ptr&lt;Abstract&gt;(ptr);
      vectorShared.push_back(shared);
      uniquePtr.release();
  }
  </code></pre>
  
  <p>Is there a better way to do this?</p>