I cannot tell what is wrong with my move assignment operator, here is the function. I don't think I am grabbing the data correctly, because when I run the test I get a random negative number and a "you're program has stopped working)
virtual LinkedList<T> &operator=(LinkedList<T> &&other)
{
cout << " [x] Move *assignment* operator called. " << endl;
// Delete our own elements
ListNode<T> *temp1 = _front;
while (temp1 != nullptr)
{
ListNode<T> *n = temp1->getNext();
delete temp1;
temp1 = n;
}
// Grab other data for ourselves
ListNode<T> *temp2 = other._front;
while (temp2 != nullptr)
{
addElement(temp2->getValue());
temp2 = temp2->getNext();
}
// Reset their pointers to nullptr
other._front = nullptr;
other._end = nullptr;
other._size = 0;
other._last_accessed_index = 0;
other._last_accessed_node = nullptr;
return *this;
}
Test Code- this is my teachers test code -
// Use move *assignment* operator
cout << " [x] Test #5: Move *assignment* constructor behavior" << endl;
moved1 = LinkedList<int>{ 6, 7, 8, 9, 10 };
cout << " [x] Result:" << endl;
cout << " [x] Expected:\t6 7 8 9 10" << endl;
cout << " [x] Actual:\t\t";
for (int i = 0; i < moved1.getSize(); i++)
{
cout << moved1.getElementAt(i) << " ";
}
cout << endl << endl;
this is my first time working with move and the move assignment operator. Thanks :)