Iteration through <#7574#>Containers<#7574#> and <#7575#>Collections<#7575#> is performed
by <#7576#>Iterator<#7576#> objects. These
class instances are constructed with the address of a <#7577#>Container<#7577#> (or
<#7578#>Collection<#7578#>). Elements are retrieved subsequently using the <#7677#>()<#7677#> operator,
which returns 1 while elements remain, then returns 0.
For example, consider Figure~#fig:iterator1#7559>.
<#7560#>
Figure 2.3:
Use of <#7723#>Iterator<#7723#>
#figure7560# |
<#7560#>
More than one iterator may operate on a given <#7724#>Container<#7724#> at
once; however, removal of elements from within the iteration loop can
corrupt the iteration scheme.
Note that <#7725#>Iterators<#7725#> make the definition of copy constructor member
functions almost trivial. Any new data structure class may define a
constructor which takes an argument of type (<#7721#><#7726#>Container<#7726#><#7721#><#7736#>;SPMlt;<#7736#>Item<#7738#>;SPMgt;<#7738#>&).
The body of the constructor simply iterates through the elements of the
passed <#7727#>Container<#7727#> and inserts them into the structure under
construction.