remove() Functions
To search for and remove particular items, you can use the functions remove() and removeAndDestroy():
virtual RWCollectable* remove(const RWCollectable*);
virtual void removeAndDestroy(const RWCollectable*);
The function remove() looks for an item that is equal to its argument and removes it from the collection, returning a pointer to it. It returns nil if no item is found.
The function
removeAndDestroy() is similar except it deletes the item instead of returning it, using the virtual destructor inherited by all
RWCollectable items. You must be careful when using this function that the item was actually allocated off the heap,
not the stack, and that it is
not shared with another collection.
The following example, which expands on the previous one, demonstrates the use of the virtual function removeAndDestroy():
RWCollectable* oust = sc.remove(&dummy); //11
delete oust; //12
sc.removeAndDestroy(&dummy); //13