Chapter 28

Inheriting a Class

In This Chapter

arrow Introducing inheritance

arrow Implementing inheritance in C++

arrow Reviewing an example program

arrow Comparing HAS_A to IS_A

Inheritance occurs all around us every day. I am human; I inherit certain properties from the class Human, such as my ability to converse intelligently (more or less) and my dependence on air, water, and carbohydrate-based nourishment like Twinkies. These latter properties are not unique to humans. The class Human inherits these from class Mammal (along with something about bearing live young), which inherits other properties from class Animal, and so on.

The capability to pass down properties is a powerful one. It enables you to describe things in an economical way. For example, if my son asks me, “What’s a duck?” I might say, “It’s a bird that floats and goes quack.” Despite your first reaction, that answer actually conveys a significant amount of knowledge. My son knows what a bird is. He knows that birds have wings, that birds can fly (he doesn’t know about ostriches yet), and that birds lay eggs. Now, he knows all those same ...

Get Beginning Programming with C++ For Dummies, 2nd Edition 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.