template<class T> T sqrt (T);
template<class T> complex<T> sqrt(complex<T>);
double sqrt(double);
void f(complex<double> z)
{
sqrt(z);
}
In this code how does sqrt<double>(complex<double>) end up as a candidate for
template argument deduction?
And the author says any call that matches sqrt<T>(complex<T>) also matches sqrt<T>(<T>). How?
Code is from The C++ Programming Language, by Bjarne Stroustrup. Section 13.3.2
Well,
zis of typecomplex<double>. WithTbeingdoubleit clearly matchesAlso, with
Tbeingcomplex<double>it matchesWhere is the problem with this?
As the result of matching both of these functions, the overload set for deciding which of the functions to use consists of the two instantiations
Both match but the first one is more specialized and, thus, chosen by the overload resolution.