Chapter 4: Class Features

Enumerated constants help to document the use of constants in a class and should be used whenever possible. Enumerated types are usually given public access, and when used outside of the class scope, must be qualified by the class name.

Classes often contain other class objects. We express this as a composition relationship and recongnize that it allows us to build powerful and complex data structures. Most applications are comprised of groups of related objects, many containing other objects.

A constructor-initializer list is used by a constructor to initialize class data members, particularly ones that are class objects. We presented the Point and Figure classes as examples of this.

Classes can contain reference and const-qualified data members. These must be initialized by the enclosing class constructor, using a constructor-initializer list. References are useful for forming a connection to an object that already exists.

Static data members are variables that belong to all instances of the same class. We showed an example of a Student class that kept a reference count of the number of instances of students created by the program. We showed how a static data member can be effectively used by a class constructor.

Static member functions provide access to static data members. They are useful for operations that involve an entire class, such as initializing static data members. We showed an example of a Rectangle class that used a static member function to set the default drawing color of all Rectangle objects.

We introduced the FString class, which implements operations on fixed-length strings. This class makes it easier to assign, initialize, copy, compare, and display strings, without having to deal directly with character arrays. We will use the FString class throughout the book.

The Robot Wars simulation program was an example of a larger program involving several interacting classes. We followed the same program development steps introduced in Chapter 2, including specifications, analysis, design, and implementation. Recognizing that no useful program is ever completely finished, we discussed ways in which the program could be improved.