We will start this section by introducing the syntax of function templates and their instantiations, deductions, and specializations. Then, we will move on to class templates and look at similar concepts, as well as examples.
Exploring function and class templates
Motivation
So far,when we have defined a function or a class, we have had to provide input, output, and intermediate parameters. For example, let's say we have a function to performs the addition of two int type integers. How do we extend this so that it handles all the other basic data types, such as float, double, char, and so on? One way is to use function overloading by manually copying, pasting, and slightly modifying each function. Another way is to define...