O'Reilly logo

C++ Without Fear: A Beginner’s Guide That Makes You Feel Smart, Second Edition by Brian Overland

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

18. Polymorphism: Object Independence

If you’ve made it this far, congratulations! You’re about to scale the highest peak of all in the mountain range of object-oriented concepts: polymorphism. It is the key to making objects truly independent.

Remember that objects—which are instances of classes—are data items that have built-in behavior. More than anything else, this ability of an unknown object to bring in new kinds of behavior—essentially plugging new software into an existing framework—makes good on the promise of object orientation.

A Different Approach to the FloatFraction Class

Virtual functions are at the core of polymorphism. To understand why they are useful, let’s look at an example building on the Fraction class.

The FloatFraction ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required