An Example of compareTo(), isEqual(), and hash()
We have described three inherited virtual functions: compareTo(), isEqual(), and hash(). Here is an example that defines a set of objects, and applies the functions. The results of the functions appear as comments in the code.
RWCollectableString a("a");
RWCollectableString b("b");
RWCollectableString a2("a");
a.compareTo(&b); // Returns -1
a.compareTo(&a2); // Returns 0 ("compares equal")
b.compareTo(&a); // Returns 1
a.isEqual(&a2); // Returns true
a.isEqual(&b); // Returns false
a.hash() // Returns 96 (operating system dependent)
Note that the
compareTo() function for
RWCollectableStrings has been defined to compare strings lexicographically in a case sensitive manner. See class
RWCString in the
SourcePro API Reference Guide for details.