title: c++: can vector<Base> contain objects of type Derived?
body: <p>The title pretty much says it all. Basically, is it legal to do this:</p>
  
  <pre><code>class Base {
      //stuff
  }
  
  class Derived: public Base {
      //more stuff
  }
  
  vector&lt;Base&gt; foo;
  Derived bar;
  foo.push_back(bar);
  </code></pre>
  
  <p>Based on other posts I've seen, the following is okay, but I don't want to use pointers in this case because it's harder to make it thread safe.</p>
  
  <pre><code>vector&lt;Base*&gt; foo;
  Derived* bar = new Derived;
  foo.push_back(bar);
  </code></pre>