I'm diving into the implicit conversions of C++20, and came up with this example:
#include <iostream>
void f(int a){ std::cout << 1; }
void f(int &a){ std::cout << 2; }
int main(){
int a = 1;
int &b = a;
f(a); // This is ambiguous
f(b); // So is this
const int c = 1;
f(c); // This works, as you cannot take a reference of a const
f(42); // So does this, normal
}
Which leaves me with the following questions:
- How can I call the second definition of f?
- If I cannot call it, why doesn't the compiler tell me so?
For 2., I'm currently learning rust (since 2 years), and am used to be informed for every stupid thing I do by the compiler...
Thanks for any help,
Linus