Tools.h++ Manual

104011 Tandem Computers Incorporated 16-3
16
Note – we have inserted one item into the collection twice. That is, two items
in the collection are identical. Graphically, the object bt looks something like
this:
The expression on line 2 called the function
RWvostream&operator<<(RWvostream&, const RWCollectable&);
which stored a shallow copy of the collection. That is, only only one copy of
“George” was stored.
As a side note, the expression on line 3 deletes all the members of the binary
tree. The function
clearAndDestroy()
has been written so that it deletes
each object only once, so that you do not have to worry about deleting the
same object too many times.
The resulting image can be read back in and faithfully restored using the
companion member function
RWvistream&operator>>(RWvistream&, RWCollectable&);
Here is how to do this:
// Store in ascii to standard output:
RWpostream ostr(cout); // 1
ostr << sc; // 2
bt.clearAndDestroy(); // 3
return 0;
}
#define RW_STD_TYPEDEFS
#include <rw/bintree.h>
#include <rw/collstr.h>
#include <rw/pstream.h>
main()
{
RWpistream istr(cin);
SortedCollection sc2;