#include<iostream> using namespace std; void foo(const long& a) { cout << "long version"; } void foo( float& a) { cout << "float version" << endl; } int main() { int a = 3; foo(a); } The example above will output "long version", however, according to C++ primer:
When we call an overloaded function that differs on whether a reference or pointer parameter refers or points to const, the compiler uses the constness of the argument to decide which function to call:
The program should output the version that does not contain the constness since they have the same arithmetic conversion precedence, but the program always chooses the one with const for some reason.
Could anyone explain to me why does the compiler choose the const version? Really appreciate your help :)