Add Definitions for Virtual Functions
Class RWCollectable declares the following virtual functions:
 
virtual ~RWCollectable();
virtual RWspace binaryStoreSize() const;
virtual int compareTo(const RWCollectable*) const;
virtual unsigned hash() const;
virtual RWClassID isA() const;
virtual bool isEqual(const RWCollectable*) const;
virtual RWCollectable* newSpecies() const;
virtual void restoreGuts(RWvistream&);
virtual void restoreGuts(RWFile&);
virtual void saveGuts(RWvostream&) const;
virtual void saveGuts(RWFile&) const;
Any class that derives from class RWCollectable should be able to understand any of these methods. Although default definitions are given for all of them in the base class RWCollectable, it is best for you as the class designer to provide definitions tailored to the class at hand.
We've split our discussion of these virtual functions. We discuss the destructor in Object Destruction, and the binaryStoreSize(), saveGuts(), and restoreGuts() functions in How to Add Polymorphic Persistence, where we describe how to add persistence to a class. Virtual functions isA() and newSpecies() are declared and defined by macros, so they were discussed above, in Virtual Function isA() and Virtual Function newSpecies(). This section presents discussion on the remaining functions: compareTo(), isEqual(), and hash(). A very brief example, showing how all three functions deal with the same data, appears in An Example of compareTo(), isEqual(), and hash().