July 2000
Intermediate to advanced
1280 pages
34h 55m
English
The C++ idea of a template is based on the assumption that the algorithm works in exactly the same way for different data types. Then writing just one class instead of writing a separate class for each type makes sense. Sometimes, however, this assumption does not hold. The algorithm works the same way for different data types, but for some types, some details of the algorithm have to be implemented differently.
Consider, for example, a template class Array that contains a set of data (of a component type) and allows the client code to check whether a given element (of the component type) can be found in the collection.
template <class T> class Array { T *data; // heap array of data int size; // size of the array Array(const ...Read now
Unlock full access