22.11. Polymorphism

Each Pop Framework game is based on a cBiota object which is a specialized kind of array of cCritter* pointers. The program executes by walking through this array and letting each of the member critters call a method. At each step of the game’s animation, for instance, we walk through the cBiota array and let each of the member cCritter pointers make a call to its virtual update method.

Rather than having to check which kind of critter we have in each slot, we’re able to just let each critter call its own version of the update method. This is what polymorphism is for. In order to make a function behave polymorphically, we have to do two things. We already mentioned this in Section 22.10: Virtual Methods, but it’s worth saying ...

Get Software Engineering and Computer Games now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.