title: When I call a function in child class it is instead calling the parent class function
body: <p>I am working on a project where I have an array of children classes.
  I want to call an overridden child function from the array, but instead it calls the parent function. </p>
  
  <pre><code>#include &lt;iostream&gt;
  
  class Parent {
  public:
      Parent(){}
      void print() {
          std::cout &lt;&lt; "I'm the parent!" &lt;&lt; std::endl;
      }
  };
  
  class ChildOne : public Parent {
  public:
      ChildOne(){}
      void print() {
          std::cout &lt;&lt; "I'm childOne!" &lt;&lt; std::endl;
      }
  };
  
  class ChildTwo : public Parent {
  public:
      ChildTwo() {}
      void print() {
          std::cout &lt;&lt; "I'm childTwo!" &lt;&lt; std::endl;
      }
  };
  
  
  int main(int argc, char const *argv[]) {
      Parent arr[] = {ChildOne(), ChildTwo()};
      int n = 2;
  
      for(int i = 0; i &lt; n; i++) {
          arr[i].print();
      }
  
      return 0;
  }
  
  </code></pre>
  
  <p>The output I get is </p>
  
  <pre><code>I'm the parent!
  I'm the parent!
  </code></pre>
  
  <p>Where the output I want is </p>
  
  <pre><code>I'm childOne!
  I'm childTwo!
  </code></pre>