Sams Teach Yourself C++ in 21 Days
456 Day 14 Adding to Two Lists ...................................................................................... The other ...
Polymorphism 457 14 LISTING14.3 Multiple Inheritance 0: // Listing 14.3. Multiple inheritance. 1: 2: #include <iostream> 3 ...
458 Day 14 48: { 49: cout << “\n(1)Horse (2)Pegasus: “; 50: cin >> choice; 51: if (choice == 2) 52: pHorse = new Peg ...
Polymorphism 459 14 Ranch[0]: Whinny!... Horse destructor... Ranch[1]: Whinny!... Pegasus destructor... Bird destructor... Horse ...
460 Day 14 The Parts of a Multiply Inherited Object ...................................................... When thePegasusobject ...
Polymorphism 461 14 12: Horse(COLOR color, HANDS height); 13: virtual ~Horse() { cout << “Horse destructor...\n”; } 14: vi ...
462 Day 14 60: return itsNumberBelievers; 61: } 62: 63: private: 64: long itsNumberBelievers; 65: }; 66: 67: Pegasus::Pegasus( 6 ...
Polymorphism 463 14 On lines 9–20, the Horseclass is declared. The constructor takes two parameters: One is an enumeration for c ...
464 Day 14 Any time you need to resolve which class a member function or member data inherits from, you can fully qualify the ca ...
Polymorphism 465 14 LISTING14.5 Common Base Classes 0: // Listing 14.5 1: // Common base classes 2: 3: #include <iostream> ...
466 Day 14 49: Bird(COLOR color, bool migrates, int age); 50: virtual ~Bird() {cout << “Bird destructor...\n”; } 51: virtu ...
Polymorphism 467 14 98: int age = pPeg->GetAge(); 99: cout << “This pegasus is “ << age << “ years old.\n”; ...
468 Day 14 The constructor initializes the Horsepart of the Pegasuswith the color, height, and age on line 88. It initializes th ...
Polymorphism 469 14 Listing 14.6 rewrites Listing 14.5 to take advantage of virtual derivation. LISTING14.6 Illustration of the ...
470 Day 14 26: { 27: public: 28: Horse(COLOR color, HANDS height, int age); 29: virtual ~Horse() { cout << “Horse destruct ...
Polymorphism 471 14 75: virtual COLOR GetColor()const { return Horse::itsColor; } 76: private: 77: long itsNumberBelievers; 78: ...
472 Day 14 Pegasusno longer has to disambiguate the call to GetAge(), and so is free to simply inherit this function from Animal ...
Polymorphism 473 14 Mixins and Capabilities Classes .................................................................... One way ...
474 Day 14 LISTING14.7 Shape Classes 0: //Listing 14.7. Shape classes. 1: 2: #include <iostream> 3: using std::cout; 4: us ...
Polymorphism 475 14 49: int itsWidth; 50: int itsLength; 51: }; 52: 53: void Rectangle::Draw() 54: { 55: for (int i = 0; i<it ...
«
20
21
22
23
24
25
26
27
28
29
»
Free download pdf