0

the main.cpp has list4 = list3 = list1 which test the overloaded operator

all the lists have 3 doubles but list 4 has an additional double appended later to it giving it 4 doubles.

I have to display all 3 lists but when displaying them the double that is added to list 4 also appears in the other 2 lists.

// Class that is in a header file
class NumberList
{
private:
   // Declare a structure for the list
   struct ListNode
   {
      double value;          
      struct ListNode *next;  
   }; 

   ListNode *head;           

public:
   
   NumberList()
        { head = NULL; }
   
   NumberList(const NumberList& origObject);

  
   NumberList& operator=(const NumberList& objToCopy);

  
   ~NumberList();
      
   // Linked list operations
   void appendNode(double);
   void insertNode(double);
   void deleteNode(double);
   void displayList() const;

//copy assignment operator
};
NumberList& NumberList::operator=(const NumberList& objToCopy){
   cout << "overlaoded operator" << endl;
   if(this != &objToCopy){
      delete head;
      head = new ListNode;
      *head = *(objToCopy.head);
   }
   return *this;
}

this is what i have for assignment operator which is what i have not been able to get to work. I believe i have to use a while loop and append. But i don't really know what to do.

0 Answers0