If there is an rvalue reference in a function overload, how to call to function? Why not call the version of the rvalue reference?
void test(int& x) {
cout << "int &x" << endl;
}
void test(const int &x) {
cout << "const int &x" << endl;
}
void test(int&& x) {
cout << "int &&x" << endl;
}
void test(const int&& x) {
cout << "const int &&x" << endl;
}
int main() {
int &&rr = 10;
const int &&crr = 10;
test(rr); // call to int &x, why not call to int &&x
test(crr); // call to const int &x, why not call to const int &&x
}
In addition, why call to 'test' is ambiguous?
void test(int x) {
cout << "int &x" << endl;
}
void test(const int&& x) {
cout << "const int &&x" << endl;
}
int main() {
int &&rr = 10;
test(10); // call to 'test' is ambiguous
test(move(rr));
}