title: Downcast unique_ptr to access a function
body: <p>How to make it work? Error/comment line before <code>return 0;</code></p>
  
  <pre><code>#include &lt;iostream&gt; 
  #include &lt;vector&gt;
  #include &lt;memory&gt;
  
  using namespace std;
  
  
  class Base 
  {
      public:   
          void foobar() { cout &lt;&lt; "foobar"; }
  };
  
  class Derived : public Base
  {
      public:
  
          void print() { cout &lt;&lt; "hello world!"; }
  };
  
  int main(int argc, char *argv[]) 
  {
      vector&lt;unique_ptr&lt;Base&gt;&gt; bases;
      bases.push_back(unique_ptr&lt;Base&gt; (new Derived()));
  
      //ok
      bases[0]-&gt;foobar();
      //error
      //how can I make this works?
      static_cast&lt;Derived*&gt; (bases[0])-&gt;print();
  
      return 0;
  }
  </code></pre>