list& operator=(const list& other) { // Remove any existing nodes we hold while(head != nullptr) { node* toDelete = head; head = head->next; delete toDelete; } // Copy over data from the other list's nodes node* current = other.head; if(current == nullptr) tail = nullptr; else { head = tail = new node(current->data); current = current->next; while(current != nullptr) { tail->next = new node(current->data); tail = tail->next; current = current->next; } } // operator= must always end with: return *this; }