title: How to add object of subclass into dynamic array of abstract baseclass?
body: <p>Example:</p>
  <pre><code>class Shape{
  public:
      virtual int getArea() = 0;
  };
  class Square : public Shape{
  public:
      Square(int h, int w):
          m_h(h),
          m_w(w){}
  
      int getArea() override{
          return m_h * m_w;
      }
  private:
      int m_h;
      int m_w;
  };
  
  class ShapeCollection{
  public:
      ShapeCollection(size_t capacity):
          m_size(0),
          m_shape_array(new Shape*[capacity]){
          for (size_t i = 0; i &lt; m_capacity; ++i)
          {
              m_shape_array[i] = nullptr;
          }
      }
      ~ShapeCollection(){
          for (size_t i = 0; i &lt; m_capacity; ++i)
          {
              delete m_shape_array[i];
          }
  
          delete[] m_shape_array;
      }
  
      void addShape(const Shape&amp; shape){ // This must the arguments.
  // I'M ONLY ASKING FOR HELP FROM HERE!
          if (m_size &gt;= m_capacity)
          {
              throw std::invalid_argument(&quot;Shape array is full&quot;);
          }
          m_shape_array[m_size] = shape; // This dosen't work.
  // TO HERE!
      }
  
  private:
      size_t m_size;
      size_t m_capacity;
      Shape** m_shape_array;
  
  };
  </code></pre>
  <p>Adding the item dynamically i.e</p>
  <pre><code>m_shape_array[m_size] = new Shape(shape);
  </code></pre>
  <p>Is not allowed due to massive amounts of errors in code of which I'm not allowed to edit.</p>
  <p>No:</p>
  <ul>
  <li>Vectors</li>
  <li>Move constructor</li>
  <li>Copy constructor</li>
  <li>Move assignment constructor</li>
  <li>Copy assignment constructor</li>
  </ul>
  <p>Just good old-fashioned manual memory handling.</p>