Tools.h++ Manual

17-4 104011 Tandem Computers Incorporated
17
Define a default constructor;
Add the macro
RWDECLARE_COLLECTABLE
to your class declaration;
Add the macro
RWDEFINE_COLLECTABLE
to a
.cc
file, to be compiled;
Add definitions for the following inherited virtual functions as necessary
(you may be able to use inherited definitions):
RWspace binaryStoreSize() const;
int compareTo(const RWCollectable*) const;
RWBoolean isEqual(const RWCollectable*) const;
unsigned hash() const;
void restoreGuts(RWFile&);
void restoreGuts(RWvistream&);
void saveGuts(RWFile&) const;
void saveGuts(RWvostream&) const;
17.4 Add a default constructor
All collectable classes are required to have a default constructor (i.e., one that
takes no arguments). This constructor will be used by the persistence
mechanism: first an “empty” object is created, then it will be “restored” with its
contents.
Because default constructors are necessary in order to create vectors of objects
in C++, providing a default constructor is a good habit to get into anyway.
Here’s a possible definition for our Bus class.
Bus::Bus() :
busNumber_ (0),
driver_ (“Unknown”),
passengers_ (rwnil)
{
}