O'Reilly logo

C++ Without Fear: A Beginner’s Guide That Makes You Feel Smart, Third 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

16. Polymorphic Poker

If the only thing that object orientation accomplished was to encourage a more modular programming style, grouping tightly related code and data together, it would still be worthwhile. But there’s more.

The central idea in OOP is that of an intelligent data type. Simply making a function into a member function is only a beginning. Ideally, objects bring with them the knowledge of which function to call; you should be able to switch out one object, switch in another, and get new behavior without changing anything else. You can even switch objects at runtime and get new behavior.

Sound like a dream? But that’s what this chapter is going to explore. We’ll start by examining the Deck class used in the previous chapter, “Object-Oriented ...

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