Including a Header That Contains a User-Defined Class
A header such as
GradeBook.h (Fig. 3.9) cannot be used as a complete program, because it does not contain a
main function. To test class
GradeBook (defined in Fig. 3.9), you must write a separate source-code file containing a
main function (such as Fig. 3.10) that instantiates and uses objects of the class.
The compiler doesn’t know what a
GradeBook is because it’s a user-defined type. In fact, the compiler doesn’t even know the classes in the C++ Standard Library. To help it understand how to use a class, we must explicitly provide the compiler with the class’s definition—that’s why, for example, to use type
string, a program must include the
<string> header. This enables the compiler to ...