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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.