3.6. Placing a Class in a Separate File for Reusability
One of the benefits of creating class definitions is that, when packaged properly, your classes can be reused by other programmers. For example, you can reuse C++ Standard Library type
string in any C++ program by including the header
<string> (and, as you’ll see, by being able to link to the library’s object code).
Programmers who wish to use our
GradeBook class cannot simply include the file from Fig. 3.7 in another program. As you learned in Chapter 2, function
main begins the execution of every program, and every program must have exactly one
main function. If other programmers include the code from Fig. 3.7, they get extra “baggage”—our
main function—and their programs will then have ...