Chapter 10: Classes: A Deeper Look, Part2
- 10.2 const (Constant) Objects and const Member Functions
- Time.h
- To specify a member function as const, insert the keyword
const after the function's parameter list.
- Time.cpp
- The fact that a member function does not modify an object
is not sufficient. You must explicitly declare it as const.
- fig10_03.cpp
- If the program attempts to invoke non-const member fuctions
on a const object, the compiler generates an error message.
- Member Initializer List (P.452)
- Erroneously Attempting to Initialize a const Data Member with an
Assignment (P.454)
- 10.3 Composition: Objects as Members of Classes
- 10.4 friend Functions and friend Classes
- Friends can access private members of a class.
- Although friend declaration can appear anywhere in the class,
conventionally it will appear first, even before the public
specifier.
- 10.5 Using the this Pointer
- Note the parentheses around *this when used with the dot member
selection operator (.). The parentheses are required because the
dot operator has higher precedence than the * operator.
- Cascaded Function Calls
- 10.6 static Class Members
- Employee.h
- Use a static data member to track the number of Employee
objects in memory
- Employee.cpp
- Initialize at global namespace scope, without including the
keyword "static". (At global namespace scope, "static" means
that item will be known only in that file.) (Honestly, it
should be "private", but at the time C language was created,
they decided to "overload" these keywords heavily. "void*" is
another example, which should be "any*".)
- In the constructor, ++count
- In the destructor, --count
- Track the number of objects
of a class (with static data member)
- 10.7 Proxy Classes
- Implementation.h
- Interface.h
- You don't need to "#include Implementation.h".
- But "forward class declaration" is required by Line 6
"class Implementation;".
- Interface.cpp
- This is the only file which knows the implementation
details (#include "Implementation.h").
- fig11_19.cpp
- Hiding private data of Implementation with a proxy class
Interface.