October 1997
Intermediate to advanced
800 pages
20h 48m
English
The template List class in “A Generic List Class with Iterators and Value Semantics” on page 460 uses the following function to copy values for overloaded assignments and copy initialization.
template <class TYPE>
void List<TYPE>::copy(const List<TYPE> & list) { // copy List
for (Iterator<TYPE> iter(list); !iter; iter++)
append(iter()); // make copy of TYPE
}
|
An iterator steps through the source List object, and append() creates a copy of each contained object. List provides value semantics and Node objects contain data; hence, this algorithm is correct. The following code fragment declares two Lists of Strings ...