As an extension to This question, i am trying to get my move assignment correct.
I have the following code:
// copy assignment operator
LinkedList<T>& operator= (LinkedList<T> other) noexcept
{
swap(*this, other);
return *this;
}
// move assignment operator
LinkedList<T>& operator= (LinkedList<T>&& other) noexcept
{
swap(*this, other);
return *this;
}
But when i try to use it, my code fails to compile.
First some code:
LinkedList<int> generateLinkedList()
{
LinkedList<int> List;
List.add(123);
return List;
}
int main()
{
LinkedList<int> L;
L = generateLinkedList();
^ get an error here...
I get the following error:
main.cpp(24): error C2593: 'operator =' is ambiguous
linkedlist.h(79): note: could be 'LinkedList &LinkedList::operator =(LinkedList &&) noexcept'(Points to the move assignment operator)
linkedlist.h(63): note: or 'LinkedList &LinkedList::operator =(LinkedList) noexcept' (Points to the copy assignment operator)
main.cpp(24): note: while trying to match the argument list '(LinkedList, LinkedList)'
Are my move assignment operator wrong, or do i use it the wrong way?