This is clearly not the same question as Overload resolution between object, rvalue reference, const reference. Please do not close this question. In the previous question an int
is being passed while here an int &&
is being passed.
I thought I understood rvalue references but evidently I am missing something when it comes to function overloading. Given the code:
#include <iostream>
#include <utility>
void afunc(int)
{
std::cout << "\nafunc(int)\n";
}
void afunc(int &&)
{
std::cout << "\nafunc(int &&)\n";
}
int main()
{
int i = 0;
afunc(std::move(i));
}
I would have assumed that the second call to afunc
would be chosen, but instead I get that the error that the call to afunc
is ambiguous. Since std::move(i)
, as I understand it, creates an rvalue reference to i
, an int
, I do not understand why the second call to afunc
does not match exactly. Can someone please explain what I am understanding that is wrong ?