Skip to Content
Navigating C++ and Object-Oriented Design
book

Navigating C++ and Object-Oriented Design

by Paul Anderson, Gail Anderson
October 1997
Intermediate to advanced
800 pages
20h 48m
English
Pearson
Content preview from Navigating C++ and Object-Oriented Design

9.4. Overloading Template Functions

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; ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Exploring C++20: The Programmer's Introduction to C++

Exploring C++20: The Programmer's Introduction to C++

Ray Lischner

Publisher Resources

ISBN: 0135327482Purchase book