title: C++11 way of storing a polymorphic object in a class
body: <p>Before C++11, I would have implemented a class Foo, containing a polymorphic object of base-class Bar as:</p>
  
  <pre><code>struct Foo {
  
    Bar* m_b;
  
    Foo(Bar* b) : m_b(b) {}
  
  }; 
  </code></pre>
  
  <p>Following Scott Meyer's advice that raw pointers are bad, I would like to implement <code>Foo</code> in the C++11 way, but I don't know how this would look.</p>
  
  <p>I started writing it like</p>
  
  <pre><code>struct Foo {
  
    std::unique_ptr&lt;Bar&gt; m_b;
  
    Foo(std::unique_ptr&lt;Bar&gt; b) : m_b(std::move(b)) {}
  
  };
  </code></pre>
  
  <p>but this has the drawback that <code>b</code> has to be dynamically allocated. </p>
  
  <p>So what is the C++11 way of implementing a class containing a polymorphic object?</p>