|
|
|
|
|
|
|
Testing and Debugging Hints |
|
|
|
|
|
|
|
|
1. Review the Testing and Debugging Hints for Chapter 15. They apply to the design and testing of C++ classes, which are at the heart of OOP. |
|
|
|
|
|
|
|
|
2. When using inheritance, don't forget to include the word public when declaring the derived class: |
|
|
|
|
|
|
|
|
class DerivedClass : public BaseClass
{
.
.
.
}; |
|
|
|
 |
|
|
|
|
The word public makes BaseClass a public base class of DerivedClass. That is, clients of DerivedClass can apply any public BaseClass operation (except constructors) to a DerivedClass object. |
|
|
|
|
|
|
|
|
3. The header file containing the declaration of a derived class must #include the header file containing the declaration of the base class. |
|
|
|
|
|
|
|
|
4. Although a derived class inherits the private and public members of its base class, it cannot directly access the inherited private members. |
|
|
|
|
|
|
|
|
5. If a base class has a constructor, it is invoked before the derived class's constructor is executed. If the base class constructor requires parameters, you must pass these parameters using a constructor initializer: |
|
|
|
|
|
|
|
|
DerivedClass::DerivedClass( )
: BaseClass(param1, param2)
{
.
.
.
} |
|
|
|
 |
|
|
|
|
If you do not include a constructor initializer, the base class's default constructor is invoked. |
|
|
|
|
|
|
|
|
6. If a class has a member that is an object of another class and this member object's constructor requires parameters, you must pass these parameters using a constructor initializer: |
|
|
|
|
|
|
|
|
SomeClass::SomeClass( )
: memberObject(param1, param2)
{
.
.
.
} |
|
|
|
|
|