In C++11, we get an ambiguity error from the compiler (g++) if we make the following definitions:
C& operator=(C rhs)
{
swap(*this, rhs);
return *this;
}
C& operator=(C&& rhs)
{
swap(*this, rhs);
return *this;
}
It is not entirely clear to me why there is an ambiguity. In my understanding, the compiler can tell apart what is an rvalue object and what is not at compile time. So it could make a decision to call the latter for rvalue objects and the former for lvalue objects. I am probably missing something basic but an explanation would be great.