Some time ago I was confused by the following behavior of some code when I wanted to write a is_callable
trait. Overload resolution won\'t call fu
Overload resolution picks the function that is the closest match to the supplied argument. You supplied a Test. No conversion necessary -- identity conversion used. Thus function resolution chooses f(Test). Test can't be copied from rvalue, which you supplied, but overload resolution has succeeded already...conversion to int is never checked.
g(Eater)
is chosen because the types don't exactly match, the identity conversion is NOT used, and the compiler has to find a conversion routine that works. g(Slurper)
doesn't because you can't make one out of the supplied argument.
"Why doesn't this one fail: struct A { operator int(); }; void f(A&); void f(int); void g() { f(A()); }
"
Because f(A&) is not a viable overload for the supplied argument. In this case the parameter is a reference and the fact that temps don't bind to non-const is allowed to effect the resolution. In this case it does and the that version of the function becomes a non-candidate, leaving only the one and it works.