Sams Teach Yourself C++ in 21 Days
...
DAY 16 WEEK 2 Advanced Inheritance So far, you have worked with single and multiple inheritance to create is-a relationships. To ...
As an illustration, consider classes such as a Nameclass and an Addressclass: Class Name { // Class information for Name }; Clas ...
Advanced Inheritance 539 16 18: String operator+(const String&); 19: void operator+=(const String&); 20: String & op ...
69: // copy constructor 70: String::String (const String & rhs) 71: { 72: itsLen=rhs.GetLen(); 73: itsString = new char[itsL ...
Advanced Inheritance 541 16 117: // on const objects (see copy constructor!) 118: char String::operator[](int offset) const 119: ...
Listing 16.1 provides a Stringclass much like the one used in Listing 13.12 of Day 13. The significant difference here is that t ...
Advanced Inheritance 543 16 25: private: 26: String itsFirstName; 27: String itsLastName; 28: String itsAddress; 29: long itsSal ...
76: 77: cout << “Name: “; 78: cout << Edie.GetFirstName().GetString(); 79: cout << “ “ << Edie.GetLastNa ...
Advanced Inheritance 545 16 Accessing Members of the Aggregated Class ................................................ A class t ...
Cost of Aggregation........................................................................................ When you have aggreg ...
Advanced Inheritance 547 16 30: }; 31: 32: Employee::Employee(): 33: itsFirstName(“”), 34: itsLastName(“”), 35: itsAddress(“”), ...
81: cout << Edie.GetFirstName().GetString(); 82: cout << “ “ << Edie.GetLastName().GetString(); 83: cout <& ...
Advanced Inheritance 549 16 On lines 81–87, the strings in the Employeeobject are destroyed as the Employeeobject falls out of s ...
22: void SetAddress(const String & address) 23: { itsAddress = address; } 24: void SetSalary(long salary) { itsSalary = sala ...
Advanced Inheritance 551 16 70: void rPrintFunc(const Employee&); 71: 72: int main() 73: { 74: Employee Edie(“Jane”,”Doe”,”1 ...
Constructor count: 5 Name: Edythe Levine Address: 1461 Shore Parkway Salary: 20000 Constructor count: 5 String(String&) cons ...
Advanced Inheritance 553 16 You could create a new PartsCatalogclass and have it contain a PartsList. The PartsCatalogcould dele ...
repeat. The PartsCataloghas unique entries that are not ordered. The fifth member of the PartsCatalogis not part number 5. Certa ...
Advanced Inheritance 555 16 36: virtual void Display() const 37: { 38: Part::Display(); 39: cout << “Model Year: “; 40: co ...
«
24
25
26
27
28
29
30
31
32
33
»
Free download pdf