I've browsed a few threads with the same title as this but can't find anything that has helped me figure this out...
The following is a scan of a little example from "The C++ Programming Language", Second Edition, B Stroustrup, section 13.3.2 (page 336).
I don't understand the third sqrt(z)
overload resolution. I expected that the resolution would have been sqrt<complex<double>>(complex<double>)
.
Obv the function double sqrt(double)
doesn't fit the bill. But I also thought template<class T>T sqrt(T)
couldn't be resolved to sqrt<double>(complex<double>)
as this seems to me to imply T
has two different resolutions which I would have thought it can't... T
must be the same thing throughout it's "scope".
Is there something I have misunderstood and could you point it out? :) Thanks!
The second one is a speciallization wich fits the call. The parameter is T, that is, the type in
complex<T>
then the function is
sqrt<double>
Remember that the compiler selects the most speciallized template function.
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