template<typename TA, typename TB>
void foo (TA a, TB b); // #1
template<typename T>
void foo (T a, T b); // #2
int a, b;
foo(a, b);
In this case, foo #2 is called. Why?
If you were to make explicit the template parameters, you would use:
foo<int, int>(a, b);
to call the first function.
You would use:
foo<int>(a, b);
to call the second function.
Since you let the compiler choose the function, it chose the more restrictive function, which is the second one.
Why is the second one more restrictive? The compiler has to deduce one type to use the second function. It has to deduce two types to use the first one.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With