title: Why use a parent pointer to point to a child class?
body: <p>We can just use a child pointer instead. In this case we won't need any virtual functions as well. Why do we do it??</p>
  
  <p>Edit:</p>
  
  <p>All i want to know why is the code :</p>
  
  <pre><code>class enemy {
     virtual void attack () {}
  };
  
  class ninja : public enemy {
     void attack () {cout&lt;&lt;"A ninja is attacking"&lt;&lt;endl;}
  };
  
  
  class monster : public enemy {
     void attack () {cout&lt;&lt;"A monster is attacking"&lt;&lt;endl;}
  };
  
  int main (){
  ninja n;
  monster m;
  enemy *p1 = &amp;n;
  enemy *p2 = &amp;m;
  p1-&gt;attack;
  p2-&gt;attack;
  }
  </code></pre>
  
  <p>more professional and more used than this one (what is its advantages over this one):</p>
  
  <pre><code>class enemy {
  };
  
  class ninja : public enemy {
     void attack () {cout&lt;&lt;"A ninja is attacking"&lt;&lt;endl;}
  };
  
  
  class monster : public enemy {
     void attack () {cout&lt;&lt;"A monster is attacking"&lt;&lt;endl;}
  };
  
  int main (){
  ninja n;
  monster m;
  n.attack;
  m.attack;
  }
  </code></pre>