I'm reading C++ Templates: The Complete Guide, and in "13.7 Partial Specialization of Function Templates" author said:
To overload function templates, their function parameters must differ in some material way. Consider a function template R convert(T const&) where R and T are template parameters. We may very well want to specialize this template for R = void, but this cannot be done using overloading.
It could be done using function template overloading, right? Such as:
#include <iostream>
template <typename T, typename R>
R convert(T const&) { std:: cout << "R convert(T const&)\n"; }
template <typename T>
void convert(T const&) { std:: cout << "void convert(T const&)\n"; }
int main()
{
convert(0);
}
DEMO here, result is:
void convert(T const&)
What does author really mean?
convert(so that it will compile), then replace the call toconvert(0)` withint i=convert(0). It won't compile. - user3553031Rfor the first template, so it's never selected. - T.C.