|
|
|
|
|
|
|
Hour 7
More About Classes |
|
|
|
|
|
|
|
|
In Hour 6, Basic Classes, you learned how to declare new types by declaring classes. In this hour you'll learn how to manage your classes and how to enlist the compiler in helping you find and avoid bugs. In this hour you will learn |
|
|
|
|
|
|
|
|
What constant member functions are |
|
|
|
|
|
|
|
|
How to separate the class interface from its implementation |
|
|
|
|
|
|
|
|
New Term: If you declare a class member function to be const, you are promising that the method won't change the value of any of the members of the class. To declare a class method as constant, put the keyword const after the parentheses but before the semicolon. The declaration of the constant member function SomeFunction() takes no arguments and returns void. It looks like this: |
|
|
|
|
|
|
|
|
void SomeFunction() const; |
|
|
|
|
|
|
|
|
Accessor functions are often declared as constant functions by using the const modifier. The Cat class has two accessor functions: |
|
|
|
|
|