Chapter 7. Polymorphism

Along with data abstraction, inheritance and polymorphism form the basic set of tools necessary for object-oriented programming. The implementation of polymorphism in C++ is efficient and flexible but complex.

In this chapter, we'll see how the flexibility offered by C++'s implementation of polymorphism is often abused, and we'll offer guidelines for taming its complexity. Along the way, we'll examine how inheritance and virtual functions are implemented and how that implementation reflects in turn on the C++ language itself.

Gotcha #69: Type Codes

One of the surest signs of “my first C++ program” is the presence of a type code as a class data member. (I used them in my first C++ program, and they caused me no end of ...

Get C++ Gotchas: Avoiding Common Problems in Coding and Design now with the O’Reilly learning platform.

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