October 1997
Intermediate to advanced
800 pages
20h 48m
English
Overloading template functions is similar to overloading nontemplate functions (see “Function Overloading” on page 262). Template functions with the same name must have unique signatures (different argument types and/or a different number of arguments). Remember that a template function's return type is not part of its signature.
To demonstrate overloading template functions, let's write a version of max() that determines a maximum in a generic array and let's also use our previous version of max() in the same program.
template <class TYPE> // maximum in generic array TYPE max(const TYPE *array, int size) { TYPE maxv = array[0]; for (int i = 1; i < size; i++) if (array[i] > maxv) maxv = array[i]; return maxv; ...