UPDATE at the bottom.
I want make void tree::operator = ( tree t ) to use the rvalue one.(in this case, in general I want to handle them differently because of efficiency)
I've coded it, used std::move to ensure it will use rvalue, but compiler is saying it doesn't know which operator to choose. Shouldn't he choose that one using rvalues?
Code:
void tree::operator = ( tree&& t )
{
std::swap(this->pntr, t.pntr);
}
void tree::operator = ( tree t )
{
*this = std::move(t);
}
Compiler error:
tree.cpp:23:9: error: use of overloaded operator '=' is ambiguous (with operand types 'tree' and 'typename remove_reference<tree &>::type' (aka 'tree'))
*this = std::move(t);
~~~~~ ^ ~~~~~~~~~~~~
tree.cpp:16:12: note: candidate function
void tree::operator = ( tree&& t )
^
tree.cpp:21:12: note: candidate function
void tree::operator = ( tree t )
^
1 error generated.
I'm using clang-503.0.38. (but with gcc 4.8 is the same error)
UPDATE
Ok, now I have:
tree& tree::operator = ( tree&& t )
{
std::swap(this->pntr, t.pntr);
}
tree& tree::operator = ( const tree & t )
{
*this = tree(t); // tree:tree( const tree& t )
}
And it's working. Tommorow I will post what I've learned from this as an Answer.