Tools.h++ Manual

104011 Tandem Computers Incorporated 17-7
17
never appear outside the scope of the class, we do not have to worry about the
user having access to them. Hence, we can confidently delete them in the
destructor, knowing that no dangling pointers will be left.
Furthermore, because the set pointed to by
customers_
is a superset of the set
pointed to by passengers_, it is only necessary, indeed, it is essential, that we
only delete the contents of
customers_
.
Here’s a possible definition:
Bus::~Bus()
{
customers_.clearAndDestroy();
delete passengers_;
}
Note – the language guarantees that it is okay to call delete on the pointer
passengers_ even if it is nil.
17.7 Virtual function compareTo()
virtual int compareTo(const RWCollectable*) const
;
The virtual function
compareTo()
is used to order objects relative to each
other in the collection classes that depend on such ordering, such as
RWBinaryTree
or
RWBTree
.
Note – The function "
int compareTo(const RWCollectable*) const
"
should return a number greater than zero if self is “greater than” the argument,
a number less than zero if self is “less than” the argument, and zero if self is
“equal to” the argument. This last case is sometimes referred to as “comparing
equal”, not be be confused with “is equal” (see “Virtual function isEqual()” on
page 9).
The definition (and meaning) of whether one object is greater than, less than,
or equal to another object is left to the class designer. The default definition, as
defined in class
RWCollectable
, is to compare the two addresses of the
objects.