Sams Teach Yourself C++ in 21 Days

(singke) #1
Constructor count: 5
Name: Edythe Levine
Address: 1461 Shore Parkway
Salary: 20000
Constructor count: 5
String(String&) constructor
String(String&) constructor
String(String&) constructor
Name: Edythe Levine.
Address: 1461 Shore Parkway.
Salary: 20000
String destructor
String destructor
String destructor
Constructor count: 8
String destructor
String destructor
String destructor
String destructor
The output shows that five string objects were created as part of creating one
Employeeobject on line 74. When the Employeeobject is passed on line 82 to
rPrintFunc()by reference, no additional Employeeobjects are created, and so no addi-
tional Stringobjects are created. (They, too, are passed by reference.) You can see this
in the early part of the output where the constructure count remains at 5 and no construc-
tures are called.
When, on line 85, the Employeeobject is passed to PrintFunc()by value, a copy of the
Employeeis created, and three more string objects are created (by calls to the copy con-
structor).

Implementation in Terms of Inheritance Versus Aggregation/Delegation ..........


At times, one class wants to draw on some of the capabilities of another class. For exam-
ple, suppose you need to create a PartsCatalogclass. The specification you’ve been
given defines a PartsCatalogas a collection of parts; each part has a unique part num-
ber. The PartsCatalogdoes not allow duplicate entries and does allow access by part
number.
The listing for the Week in Review for Week 2 provides a PartsListclass. This
PartsListis well tested and understood, and you’d like to build on that when making
your PartsCatalog, rather than inventing it from scratch.

552 Day 16


ANALYSIS
Free download pdf