Operator Overloading for Queue C++

Posted by Josh on Stack Overflow See other posts from Stack Overflow or by Josh
Published on 2012-04-09T23:25:21Z Indexed on 2012/04/09 23:29 UTC
Read the original article Hit count: 216

Filed under:
|
|
|

I was trying to use the overload operator method to copy the entries of one queue into another, but I am going wrong with my function. I don't know how else to access the values of the queue "original" any other way than what I have below:

struct Node
{
  int item;
  Node* next;
};

 class Queue
{
 public:
   [...] //Extra code here
   void operator = (const Queue &original);
 protected:
   Node *front, *end;
 }

 void Queue::operator=(const Queue &original)
 {
       //THIS IS WHERE IM GOING WRONG
       while(original.front->next != NULL) {
       front->item = original.front->item;
       front->next = new Node;
       front = front->next;
       original.front = original.front->next;
       }
  }

© Stack Overflow or respective owner

Related posts about c++

Related posts about class