Chapter 11
Designing Game Code with Polymorphism
You saw how inheritance can be used to design reusable code in the last chapter. In this chapter you will learn how the power of inheritance can be unlocked in much more useful ways through the power of polymorphism. C++ supports the ability to access classes of different types through pointers to a base class, known as polymorphism. The program can determine the type of the object at runtime and call the correct method. The mechanism supplied by C++ to tell the compiler that a method can be different in the base class to any derived classes is the virtual method.
Virtual Methods
You have seen that methods in class hierarchies can be overridden, which allows the compiler to call a given method ...
Get Learn C++ for Game Development 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.