In the following example everything compiles correctly and the function "void foo(int&)" is called.
void foo(const int&) { /* implementation */ };
void foo(int&) { /* implementation */ };
int main(int argc, char** argv)
{
int i = 0;
foo(i);
return (0);
}
It's my understanding that the second function is called because both functions are an exact match but only the first one is a identity conversion and that's why it is a better match than the second function which is a qualification conversion.
void foo(const int&) { /* implementation */ };
void foo(int) { /* implementation */ };
int main(int argc, char** argv)
{
int i = 0;
foo(i);
return (0);
}
But why does the compiler complain for ambiguity in this example? As i take it, the compiler should call "void foo(int)" because both functions remain an exact match but the first function is a identity conversion and the second function also remains a qualification conversion.