You need a few more things before polymorphism can work here.
- HumanFighterShip and HumanShip need an implementation of printStats()
- an array containing a number of HumanFighterShips and HumanShips. This array should be defined as an array of SpaceShips, e.g. SpaceShip *arr; Assigning one of those two to an array entry works fine, even though the types are technically different. For example:
- possibly some HumanFighterShip- and HumanShip- specific attributes for HumanFighterShip:: printStats() and HumanShip:: printStats() to access - so that you know it's using those two functions and not SpaceShip:: printStats() (spaces added to stop : p displaying as
Then polymorphism can be demonstrated easily with:
for (int i=0; i<10; i++)