The following example shows the use of the allElementsDo function and applicators.
//main.cpp - main file
#include <iset.h>
#include <iostream.h>
#include "person.h" //person.h from the previous examples
typedef ISet<Person> AddressList;
ostream& operator<<(ostream& os, Person A)
{
return (os << endl << A.GetPersonName() << " " <<
A.GetTNumber());
}
class ListApplicator: public IConstantApplicator<Person> {
public:
IBoolean applyTo(Person const& A)
{
cout << A;
return true;
}
};
void ListFunction(AddressList const& List)
{
ListApplicator LA;
List.allElementsDo (LA);
}
void main()
{
AddressList Business;
AddressList::Cursor myCursor(Business);
Person A("Peter Black","714-50706");
Person B("Carl Render","714-540321");
Person C("Sandra Summers","x");
Person D("Mike Summers","x");
Person E;
Business.add(A);
Business.add(B);
Business.add(C);
Business.add(D);
//List of all elements in the set
ListFunction(Business);
}
This time you get the address listing using an applicator.
![]()
Introduction
to the Collection Classes
Collection Characteristics
Overview
of Iteration
Iteration
with Cursors
![]()
Adding an Element to a
Collection
Removing an Element from
a Collection
Using Cursors to
Locate and Access Elements
Using Cursors to Iterate
Over a Collection
Cursors vs. Exception
Handling
Instantiating the
Collection Classes
Troubleshooting
Problems while Using the Collection Class Library