Example – HP Integrity NonStop J-Series User Manual
Page 154

Click on the banner to return to the user guide home page.
©Copyright 1996 Rogue Wave Software
Example
To orient ourselves, we always like to start with an example. The following example uses a
SortedCollection to store and order a set of
RWCollectableString
s. SortedCollection is actually a
typedef for the Smalltalk-like collection class
RWBinaryTree
. Objects inserted into it are stored
in order according to their relative values as returned by the virtual function compareTo(). (See
Add Definitions for Virtual Functions
#define RW_STD_TYPEDEFS 1 //1
#include
#include
#include
main(){
// Construct an empty SortedCollection
SortedCollection sc; //3
// Insert some RWCollectableStrings:
sc.insert(new RWCollectableString("George")); // 4
sc.insert(new RWCollectableString("Mary")); // 5
sc.insert(new RWCollectableString("Bill")); // 6
sc.insert(new RWCollectableString("Throkmorton")); // 7
// Now iterate through the collection printing all members:
RWCollectableString* str; // 8
SortedCollectionIterator sci(sc); // 9
while( str = (RWCollectableString*)sci() ) // 10
cout << *str << endl; // 11
sc.clearAndDestroy();
return 0;
}
Program Output:
Bill
George
Mary