O'Reilly logo

Sams Teach Yourself C++ in 24 Hours, fifth edition by Rogers Cadenhead, Jesse Liberty

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Hour 9. Moving into Advanced Classes

const Member Functions

If you declare a member function to be constant with the const keyword, it indicates that the function won’t change the value of any members of the class. To declare a function as constant, put the keyword const after the parentheses, as in this example:

void displayPage() const;

Accessors used to retrieve a variable’s value, which also are called getter functions, often are constant functions. The Tricycle class from the preceding hour has two accessors:

void setSpeed(int newSpeed);int getSpeed(); ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required