title: Calling a derived function from an array of the base class
body: <p>How do you call a derived function from an array of the base class?</p>
  
  <p>Ex:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  
  class a{
  
  public:
      virtual void prnt(){
          std::cout&lt;&lt;"a"&lt;&lt;std::endl;
      }
  };
  
  class b: public a{
  
  public:
      virtual void prnt(){
          std::cout&lt;&lt;"B"&lt;&lt;std::endl;
      }
  };
  
  int main()
  {
      a array[3];
      array[0] = a();
      array[1] = b();
      array[2] = a();
  
      array[1].prnt();
  }
  </code></pre>
  
  <p>The output for this example is <code>a</code>.</p>
  
  <p>is there anyway to fix this?</p>