catcher said:
I checked the standard, It says that the common function has higher
priority than template function, when ambiguity happens. so fun(3)
will call a common function.
But I cant understand why fun<int>(3) should call a template function.
I cant find the item about it in the standard. In fact, I compiled
these codes using Intel C++, and the result is insteresting:
fun<int>(3) call a common function, not a template function.
It is quite possible that I'm not reading it correctly. Asking
in comp.std.c++ is advised. I understand it that if the template
argument list is specified, then non-template functions are not
added to the set of candidate functions. However, 14.8.3/1 has
the following sentence: "The complete set of candidate functions
includes all the function templates instantiated in this way and
all of the non-template overloaded functions of the same name"
which may be interpreted that only the NAME ('fun' in your case)
is going to be considered for identification purposes.
However, after further search I found 14.3/7, which says, "When
the template in a template-id is an overloaded function template,
both non-template functions in the overload set and function
templates in the overload set for which the template-arguments do
not match the template-parameters are ignored. If none of the
function templates have matching template-parameters, the program
is ill-formed." [To help understand, "template-id" is formed by
an identifier followed by an optionally empty set of angle brackets,
as in "fun<int>"]
That seems pretty straight-forward to me. 'fun<int>' should force
the compiler to ignore 'fun' or 'fun<double>' or whatever else is
out there.
Victor