Chapter 9. Class Inheritance and Virtual Functions

WHAT YOU WILL LEARN IN THIS CHAPTER:

  • How inheritance fits into object-oriented programming

  • Defining a new class in terms of an existing one

  • How to use the protected keyword to define a new access specification for class members

  • How a class can be a friend to another class

  • How to use virtual functions

  • Pure virtual functions

  • Abstract classes

  • When to use virtual destructors

In this chapter, you're going to look into a topic that lies at the heart of object-oriented programming (OOP): class inheritance. Simply put, inheritance is the means by which you can define a new class in terms of one you already have. This is fundamental to programming in C++, so it's important that you understand how inheritance works.

OBJECT-ORIENTED PROGRAMMING BASICS

As you have seen, a class is a data type that you define to suit your own application requirements. Classes in OOP also define the objects to which your program relates. You program the solution to a problem in terms of the objects that are specific to the problem, using operations that work directly with those objects. You can define a class to represent something abstract, such as a complex number, which is a mathematical concept, or a truck, which is decidedly physical (especially if you run into one on the highway). So, as well as being a data type, a class can also be a definition of a set of real-world objects of a particular kind, at least to the degree necessary to solve a given problem.

You can ...

Get Ivor Horton's Beginning Visual C++® 2010 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.