I'm trying to overload the assignment operator. The objective is to copy two linked lists.
I copy the first element fine, but for some reason the second loop around I encounter a null pointer and my loop ends on me. My brain is fried from over-studying and I can't think straight. What am I missing here?
LinkedList &LinkedList::operator=(const LinkedList &origList){
if(this != &origList){
this->~LinkedList();
NodePointer origPtr, lastPtr;
origPtr = origList.first;
lastPtr = new Node(origPtr->data);
first = lastPtr;
while(lastPtr != NULL){
lastPtr = new Node(origPtr->data);
lastPtr = lastPtr->next;
}
}
return *this;
}