A SERVICE OF

logo

The Add function adds a member to the array It takes a single parameter. ,
a reference to an object of the array type. For example, adding a TP into
object to a TP ints array would look something like this:o
// Construct a TPoints array (an array of TPoint objects)
TPoints Points(10, 0, 10);
// Construct a TPoint object
TPoint p(3,4);
// Add the TPoint object p to the array
Points.Add(p);
The Flush function clears all the members of an array and resets the
number of array members back to the initial array size. It takes no
parameters. T clear the array in the sample code above, the function callo
would look something like this:
// Clear all members in the Points array
Points.Flush();
The GetItemsInContainer function returns the total number of items in the
container Note that this number indicates the number of actual objects.
added to the container not the space available. For example, even though,
the container may have enough room for 30 objects, it might only contain
23 objects. In this case, GetItemsInContainer would return 23.
Iterators—in this case the TP intsIterator type—let you move through theo
TP intsIteratoro
array accessing a single member of the array at a time. An iterator,
constructor takes a single parameter a reference to a T rray of objects (the, A
type of objects in the array is set up by the definition of the iterator). Here’s
what an iterator looks like when it’ set up using the Line member of thes
TMyWindow class:
TPointsIterator i(*Line);
Note that Line is dereferenced because the iterator constructor takes a
TP ints & for its parameter and Line is a TP ints *. Dereferencing theo , o
pointer makes Line comply with the iterator constructor type requirements.
Once you’ e created an iterator you can use it to access each object in thev ,
array one at a time, starting with the first member In the tutorial, .
application, the iterator isn’t used very much and you won’t learn much
about the possibilities of an iterator from it. But the tutorial does use two
properties of iterators that require a note of explanation:
Y u can move through the objects in the array using the ++ operator ono
the iterator This returns a reference to the current object and increments.
the iterator to the next object in the array The order in which it performs.
these two actions depends on whether you use the ++ operator as a prefix
Chapter 2, Learning ObjectWindows
47