- Examples
Let's check out the examples of template arguments.
We'll cover the following...
We'll cover the following...
Example 1: Deduction of Template Arguments
Explanation
In the above example, we have defined 3 function templates
isSmallertakes two arguments which have the same type and returnstrueif the first element is less than the second element (line 6). Invoking the function with arguments of different types would give a compile-time error (line 25).isSmaller2takes two arguments which can have a different type. The function returnstrueif the first element is less than the second element (line 11).addtakes two arguments which can have different types (line 16). The return type must be specified because it cannot be deduced from the function arguments.
Example 2: Template Default Arguments
...