Chapter     10

Building Games with Inheritance

Being a productive video game developer involves writing well-organized code that can be reused as often as possible. C++ classes provide a feature named inheritance that helps us achieve both of these goals. Inheritance allows us to create generalized base classes that can be derived from to create classes with a more specific purpose. In this chapter you learn how this allows us to share behavior among classes.

Inheriting from a Base Class

The classic example used to explain inheritance to new programmers is that of motor vehicles. There are multiple categories of vehicles, including cars, motorbikes, and trucks. All of these things can be thought of as vehicles and therefore can be included in ...

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.