O'Reilly logo

C++ All-In-One For Dummies®, 2nd Edition by Jeff Cogswell, John Paul Mueller

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

Chapter 4. Advanced Class Usage

In This Chapter

  • Using polymorphism effectively

  • Adjusting member access between private, protected, and public when deriving new classes

  • Multiple-inheriting new classes

  • Making virtual inheritance work correctly

  • Keeping your friends straight, especially in class

  • Putting one class or type inside another

Classes are amazingly powerful. You can do so much with them. In this chapter, we talk about many of the extra features you can use in your classes. But these aren't just little extras that you may want to use on occasion. If you follow the instructions in this chapter, you should find that your understanding of classes in C++ will greatly improve, and you will want to use many of these topics throughout your programming.

We also talk about many issues that come up when you are deriving new classes and inheriting members. This discussion includes virtual inheritance and multiple inheritance, topics that people mess up a lot. We describe the ways you can put classes and types inside other classes, too.

Inherently Inheriting Correctly

Without inheritance, doing object-oriented programming would be nearly impossible. Yes, you could divide your work into objects, but the real power comes from inheritance. However, you have to be careful when using inheritance, or you can really mess things up. In the sections that follow, we talk about different ways to use inheritance and how to keep it all straight.

Morphing your inheritance

Polymorphism refers to using one object ...

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