title: Multilevel inheritance/polymorphism and virtual function
body: <p>I have a multilevel inheritance (from Ship class -> MedicShip class -> Medic class) with virtual function code as below. I suppose the result should be :</p>
  
  <p>Medic   10<br>
  Medic   10</p>
  
  <p>But it generated strange result. On the other hand, if I only use one level inheritance (from Ship class -> Medic class without MedicShip class in between) the result will be OK. Could you find my mistake please? Many thank....</p>
  
  <pre><code>#ifndef FLEET_H
  #define FLEET_H
  #include &lt;string&gt;
  #include &lt;vector&gt;
  
  using namespace std;
  
  class Ship
  {
      public:
          Ship(){};
          ~Ship(){};
          int weight;
          string typeName;
  
          int getWeight() const;
          virtual string getTypeName() const = 0;
  };
  
  class MedicShip: public Ship
  {
      public:
          MedicShip(){};
          ~MedicShip(){};
          string getTypeName() const;
  };
  
  class Medic: public MedicShip
  {
      public:
          Medic();
  };
  
  class Fleet
  {
      public:
          Fleet(){};
          vector&lt;Ship*&gt; ships;
          vector&lt;Ship*&gt; shipList() const;
  };
  #endif // FLEET_H
  
  
  
  #include "Fleet.h"
  #include &lt;iostream&gt;
  
  using namespace std;
  
  vector&lt;Ship*&gt; Fleet::shipList() const
  {
      return ships;
  }
  
  int Ship::getWeight() const
  {
      return weight;
  }
  
  string Ship::getTypeName() const
  {
      return typeName;
  }
  
  string MedicShip::getTypeName() const
  {
      return typeName;
  }
  
  Medic::Medic()
  {    
      weight = 10;    
      typeName = "Medic";
  }
  
  int main()
  {
      Fleet fleet;
      MedicShip newMedic;
  
      fleet.ships.push_back(&amp;newMedic);
      fleet.ships.push_back(&amp;newMedic);
  
      for (int j=0; j&lt; fleet.shipList().size(); ++j)
      {
          Ship* s =  fleet.shipList().at(j);
          cout &lt;&lt; s-&gt;getTypeName() &lt;&lt; "\t" &lt;&lt; s-&gt;getWeight() &lt;&lt; endl;
      }
  
      cin.get();
      return 0;
  }
  </code></pre>