title: Creating a container to store multiple types
body: <p>I have a class which contains pure virtual functions. I am using this class to make sure I do not forget to implement some methods in derived classes. </p>
  
  <p>I have a collection of derived classes like </p>
  
  <pre><code>class B : public A
  class C : public A
  class D : public A 
  etc
  </code></pre>
  
  <p>How can I create a container that can hold all of these derived classes (B,C,D)? I would prefer to use a standard container such as vector. I tried creating a vector of the base class but this results in the derived classes being converted if they are pushed onto the vector leading to a compilation error of invalid new-expression of abstract class type.</p>
  
  <p>My base class:</p>
  
  <pre><code>class A
  {
  public:
      A();
      virtual ~A();
  
      virtual double GetVolume() = 0;
  };
  </code></pre>
  
  <p>Example derived class:</p>
  
  <pre><code>class B : public A
  {
  public:
      B(){};
      virtual ~B(){};
  
      double GetVolume(){};
  };
  </code></pre>