title: C++: Vector of objects vs. vector of pointers to new objects?
body: <p>I am seeking to improve my C++ skills by writing a sample software renderer. It takes objects consisting of points in a 3d space and maps them to a 2d viewport and draws circles of varying size for each point in view. Which is better:</p>
  
  <pre><code>class World{
      vector&lt;ObjectBaseClass&gt; object_list;
  public:
      void generate(){
          object_list.clear();
          object_list.push_back(DerivedClass1());
          object_list.push_back(DerivedClass2());
  </code></pre>
  
  <p>or...</p>
  
  <pre><code>class World{
      vector&lt;ObjectBaseClass*&gt; object_list;
  public:
      void generate(){
          object_list.clear();
          object_list.push_back(new DerivedClass1());
          object_list.push_back(new DerivedClass2());
  </code></pre>
  
  <p>?? Would be using pointers in the 2nd example to create new objects defeat the point of using vectors, because vectors automatically call the DerivedClass destructors in the first example but not in the 2nd? Are pointers to new objects necessary when using vectors because they handle memory management themselves as long as you use their access methods? Now let's say I have another method in world:</p>
  
  <pre><code>void drawfrom(Viewport&amp; view){
      for (unsigned int i=0;i&lt;object_list.size();++i){
          object_list.at(i).draw(view);
      }
  }
  </code></pre>
  
  <p>When called this will run the draw method for every object in the world list. Let's say I want derived classes to be able to have their own versions of draw(). Would the list need to be of pointers then in order to use the method selector (->) ?</p>