HP Integrity NonStop J-Series User Manual
Page 200

Notice that example one creates and saves a collection that includes two copies of the same
object and two other objects. The four objects have three different types. When example one
saves the collection and when example two restores the collection, we see that:
The morphology of the collection is maintained;
●
The process that restores the collection does not know the object's type before it restores
that object.
●
Here's the first example:
#include
#include
#include
#include
#include
main(){
// Construct an empty collection
RWOrdered collection;
// Insert objects into the collection.
RWCollectableString* george;
george = new RWCollectableString("George");
collection.insert(george); // Add the string once
collection.insert(george); // Add the string twice
collection.insert(new RWCollectableInt(100));
collection.insert(new RWCollectableDate(3, "May", 1959));
// "Store" to cout using portable stream:
RWpostream ostr(cout);
ostr << collection;
// The above statement calls the insertion operator:
// Rwvistream&
// operator<<(RWvistream&, const RWCollectable&);
// Now delete all the members in collection.
// 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.
collection.clearAndDestroy();
return 0;
}