Interface Versus Implementation

As you've learned, clients are the parts of the program that create and use objects of your class. You can think of the interface to your class—the class declaration—as a contract with these clients. The contract tells what data your class has available and how your class will behave.

For example, in the Cat class declaration, you create a contract that every Cat will know and be able to retrieve its own age, that you can initialize that age at construction and set it or retrieve it later, and that every Cat will know how to Meow().

If you make GetAge() a const function (as you should), the contract also promises that GetAge() won't change the Cat on which it is called.

Why Use the Compiler to Catch Errors?

The ...

Get Sams Teach Yourself C++ in 24 Hours, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.