title: unique_ptr to a derived class as an argument to a function that takes a unique_ptr to a base class
body: <p>I'm trying to use a <code>unique_ptr</code> to derived class in a function that takes a <code>unique_ptr</code> to a base class. Something like:</p>
  <pre><code>class Base {};
  
  class Derived : public Base {};
  
  void f(unique_ptr&lt;Base&gt; const &amp;base) {}
  
  …
  
  unique_ptr&lt;Derived&gt; derived = unique_ptr&lt;Derived&gt;(new Derived);
  f(derived);
  </code></pre>
  <p>If I understand <a href="https://stackoverflow.com/a/8114913/41071">this answer</a> correctly, this code should work, but it causes the following compile errors:</p>
  <blockquote>
  <p>error C2664: 'f' : cannot convert parameter 1 from 'std::unique_ptr&lt;_Ty&gt;' to 'const std::unique_ptr&lt;_Ty&gt; &amp;'</p>
  <p>IntelliSense: no suitable user-defined conversion from &quot;std::unique_ptr&lt;Derived, std::default_delete&lt;Derived&gt;&gt;&quot; to &quot;const std::unique_ptr&lt;Base, std::default_delete&lt;Base&gt;&gt;&quot; exists</p>
  </blockquote>
  <p>If I change <code>f</code> to take <code>unique_ptr&lt;Derived&gt; const &amp;derived</code>, it works fine, but that's not what I want.</p>
  <p>Am I doing something wrong? What can I do to work around this?</p>
  <p>I'm using Visual Studio 2012.</p>