Removing an Element from a Collection

Consider the following example:

//main.cpp - main file
#include <iset.h>
#include <iostream.h>
#include "person.h" //person.h from the previous examples

typedef ISet <Person> AddressList;

IBoolean noPhone(Person const& P,void*) //predicate function
{
    return P.GetTNumber()=="x";
}

void main()
{
    AddressList business;
    Person A("Peter Black","714-50706");
    Person B("Carl Render","714-540321");
    Person C("Sandra Summers","x");
    Person D("Mike Summers","x");

    business.add(A);
    business.add(B);
    business.add(C);
    business.add(D);
    business.add(A); //Person A is added for the second time

    cout << "\nThe set now contains " << business.numberOfElements()
        <<" entries!\n";
    business.removeAll(noPhone); //Person B is removed from the set
    cout << "\nThe set now contains " << business.numberOfElements()
        <<" entries!\n";
}

If you run the program, the set will only contain 2 elements as a result of the the remove function. Try modifying the program so that all persons with a telephone number are removed when the program is run.



Introduction to the Collection Classes
Adding Elements
Removing Elements
Replacing Elements


Class Template Naming Conventions
Possible Implementation Paths
Choosing One of the Provided Implementation Variants
Adding an Element to a Collection
Taking Advantage of the Abstract Class Hierarchy
Using Collection Notification
Instantiating the Collection Classes
Troubleshooting Problems while Using the Collection Class Library