Testing Class GradeBook
Next, we’d like to use class
GradeBook in a program. As you saw in Chapter 2, the function
main (lines 19–23) begins the execution of every program.
In this program, we’d like to call class
displayMessage member function to display the welcome message. Typically, you cannot call a member function of a class until you create an object of that class. (As you’ll learn in Section 9.14,
static member functions are an exception.) Line 21 creates an object of class
myGradeBook. The variable’s type is
GradeBook—the class we defined in lines 8–16. When we declare variables of type
int, as we did in Chapter 2, the compiler knows what
int is—it’s a fundamental type that’s “built into” C++. In line 21, ...