Templates
What this topic covers
Explain how function and class templates work, and apply type deduction when template parameters are shared. Recognize common template uses and problems, including conflicting argument types.
Why does calling a function template with mixed argument types fail when one parameter is used twice?
Template argument deduction needs every argument matched to T to give the same type. Passing an int and a double to T add(T a, T b) gives conflicting deductions, and the compiler rejects the call. Standard conversions do not fix this, so cast one argument or use two template parameters.