title: Is there a design pattern to achieve runtime polymorphism without using dynamic cast for this scenario?
body: <p>Let's say I have a class structure where parent class <strong>P</strong> stores a vector of pointers to child objects of class <strong>C</strong>. <br></p>
  
  <pre><code>class P {
  public:
  
      P() {}
  
  private:
      std:: vector&lt;C*&gt; children;
  };
  </code></pre>
  
  <p>Also, child class <code>C</code> is a base class and <strong>D</strong>,<strong>E</strong> are derived classes of C. <br>
  D and E have some unique member variables.</p>
  
  <pre><code>class C
  {
  public:
      C() {}
  
      virtual ~C() {}
      virtual void initialize() = 0;
  };
  
  class D : public C {
  public:
      void initialize() override;
  
      //Member variable unique to D
      int value;
  };
  
  class E: public C {
  public:
      void initialize() override;
  
      //Member variable unique to E
      std::vector&lt;int&gt; vector_value;
  };
  </code></pre>
  
  <p>At runtime, objects of C and D are created and added to parent P's children vector.</p>
  
  <p>At a later time I want to iterate over this vector, determine the object type and use the child's unique member variable. </p>
  
  <p>I know I can achieve this by using a dynamic cast :</p>
  
  <pre><code>for( C* child : children)
  {
     D* d_child = dynamic_cast&lt;D*&gt;(child);
     if( d_child != nullptr)
     {
        // This object is of type D 
        do something with  d_child-&gt;value ...
     }
     else
     {
        // This object is of type E
         do something with  d_child-&gt;vector_value...
     }
  }
  </code></pre>
  
  <p>However, it is a bad design when we have to check types as iterated by many answers here <a href="https://stackoverflow.com/questions/2355195/check-for-derived-type-c">Check for derived type (C++)</a></p>
  
  <p>So I want to know if there is a standard way or a design pattern that will help me achieve this functionality in a better manner?</p>