Tools.h++ Manual
104011 Tandem Computers Incorporated 14-9
14
Program output:
1
2
3
4
The items are appended at the tail of the list (see Part 2: Class Reference). For
each item, the
apply()
function calls the user-defined function
printAFoo()
with the address of the item as the first argument and the address of an
ostream (an output stream) as the second argument. The job of
printAFoo()
is to print out the value of member data val. Because
apply()
scans the list
from beginning to end, the items will come out in the same order in which they
were inserted.
With some care, apply functions can be used to change the objects in a
collection. For example, you could use an apply function to change the value
of member data val in the example above, or to delete all member objects. But,
in the latter case, you must be careful not to use the collection again.