Chp~12 - C++ PROGRAMMING Chapter 12 Inheritance What Is...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: C++ PROGRAMMING Chapter 12 Inheritance What Is Inheritance? Inheritance and Derivation Figure 12.1. The Animal Kingdom The Syntax of Derivation Listing 12.1. Simple inheritance . Private Versus Protected Listing 12.2. Using a derived object . Constructors and Destructors Listing 12.3. Constructors and destructors called . Passing Arguments to Base Constructors Listing 12.4. Overloading constructors in derived classes . Overriding Functions Listing 12.5. Overriding a base class method in a derived class. Overloading Versus Overriding Hiding the Base Class Method Listing 12.6. Hiding methods . Overriding Versus Hiding Calling the Base Method Listing 12.7. Calling base method from overridden method . Virtual Methods Listing 12.8. Using virtual methods . Listing 12.9. Multiple virtual functions called in turn . How Virtual Functions Work Figure 12.2. Figure 12.3. Figure 12.4. You Cant Get There from Here Slicing Listing 12.10. Data slicing when passing by value . Virtual Destructors Virtual Copy Constructors Listing 12.11. Virtual copy constructor . The Cost of Virtual Methods Summary Q&A Quiz , Exercises Chapter 12 Inheritance It is a fundamental aspect of human intelligence to seek out, recognize, and create relationships among concepts. We build hierarchies, matrices, networks, and other interrelationships to explain and understand the ways in which things interact. C++ attempts to capture this in inheritance hierarchies. ToChapter you will learn What inheritance is. How to derive one class from another. What protected access is and how to use it. What virtual functions are. What Is Inheritance? What is a dog? When you look at your pet, what do you see? A biologist sees a network of interacting organs, a physicist sees atoms and forces at work, and a taxonomist sees a representative of the species canine domesticus. It is that last assessment that interests us at the moment. A dog is a kind of canine, a canine is a kind of mammal, and so forth. Taxonomists divide the world of living things into Kingdom, Phylum, Class, Order, Family, Genus, and Species. This hierarchy establishes an is-a relationship. A dog is a kind of canine. We see this relationship everywhere: A Toyota is a kind of car, which is a kind of vehicle. A sundae is a kind of dessert, which is a kind of food. What do we mean when we say something is a kind of something else? We mean that it is a specialization of that thing. That is, a car is a special kind of vehicle. Inheritance and Derivation The concept dog inherits, that is, it automatically gets, all the features of a mammal....
View Full Document

Page1 / 32

Chp~12 - C++ PROGRAMMING Chapter 12 Inheritance What Is...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online