I am trying to use the overload operator constructor, but having some trouble with exceptions. Need a little help.
I have an existing deep copy that works fine, but when trying to use it from a copy using the overload =operator, it is throwing all sorts of errors.
ListClass& ListClass::operator=(const ListClass& rhs)
{
if (this != &rhs)
{
while(this->head != NULL)
{
remove (1);
}
this->head = new ListNode;
assert(head != NULL); // check allocation
this->head->item = rhs.head->item;
// copy rest of list
ListNode *newPtr = head; // new list pointer
ListNode ;
// newPtr points to last node in new list
// origPtr points to nodes in original list
for (ListNode *origPtr = rhs.head->next;
origPtr != NULL;
origPtr = origPtr->next)
{
newPtr->next = new ListNode; // link new node to end of list
assert(newPtr->next != NULL);
newPtr = newPtr->next;
newPtr->item = origPtr->item; // copy the data
newPtr->next = NULL;
}
this->head = rhs.head;
}
return *this;
}