As an illustration, consider classes such as a Nameclass and an Addressclass:
Class Name
{
// Class information for Name
};
Class Address
{
// Class information for Address
};
As an illustration of aggregation, these two classes could be included as part of an
Employeeclass:
Class Employee
{
Name EmpName;
Address EmpAddress;
// Any other employee class stuff...
}
Thus, an Employeeclass contains member variables for a name and for an address
(Employeehas-aNameand Employeehas-anAddress).
A more complex example is presented in Listing 16.1. This is an incomplete, but still
useful,Stringclass, not unlike the Stringclass created on Day 13, “Managing Arrays
and Strings.” This listing does not produce any output. Instead, Listing 16.1 will be used
with later listings.
LISTING16.1 The StringClass
0: // Listing 16.1 The String Class
1:
2: #include <iostream>
3: #include <string.h>
4: using namespace std;
5:
6: class String
7: {
8: public:
9: // constructors
10: String();
11: String(const char *const);
12: String(const String &);
13: ~String();
14:
15: // overloaded operators
16: char & operator[](int offset);
17: char operator[](int offset) const;
538 Day 16