... The name of a type parameter must be unique in the template parameter list for a particular template definition. When the compiler detects a maximum invocation in the program source code, the type of the arguments in the maximum call is substituted for T throughout the template definition, and C++ creates a complete function for determining the maximum of three values of the specified type—all three must have the same type, since we use only one type parameter in this example. Then the newly created function is compiled—templates are a means of code generation. (We’ll use C++ Standard Library templates that require multiple type parameters in Chapter 15.)

Using Function Template maximum

Figure 6.23 uses the maximum function template to determine ...

Get C++ How to Program, 10/e now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.