hopefully this code is not too obscure. lemme know and I can provide
clarification.
basically trying to implement a linked list (single links) manually.
the function below is supposed to assign the contents of one LL to
another but doesn't work.
I added the second last line to show what tempLL contains just prior to
its return and puzzlingly its contents are identical to those of the LL
to be assigned (rhs) - which is the expected result. however after the
return the destination LL holds nothing but nulls.
am I missing something ridiculously obvious?
// assignment operator resulting in deep copy
LinkedList LinkedList::operator=(const LinkedList& rhs)
{
LinkedList* tempLL;
if(this != &rhs)
{
tempLL = new LinkedList();
Node* cursor = rhs.firstNode;
while(cursor)
{
tempLL->AddToEnd(cursor->GetData());
cursor = cursor->GetNext();
}
}
else tempLL = this;
tempLL->Display();
return *tempLL;
}