title: (C++ Error: pointer being freed was not allocated) for linked lists
body: <p>With this main:</p>
  
  <pre><code>void print_first(Queue q);
  
  int main()
  {
     Queue q1;
     Queue q2(4);
     q2.push(5);
     q2.push(3);
  //   q2.print_list();
     for (int i = 0; i &lt; 3; i++)
     {
        print_first(q2);
     }
     return 0;
  }
  
  void print_first(Queue q)
  {
     if (!q.isEmpty())
     {
        cout &lt;&lt; q.pop() &lt;&lt; endl;
     }
     else
     {
         cout &lt;&lt; "Nothing in queue" &lt;&lt; endl;
     }
  }
  </code></pre>
  
  <p>and these function definitions in a class Queue which has a linked lists with "head" and "tail" as pointers to the first and last Nodes in a linked list, each node which contains another struct "data" which stores an redefined type ElementType:</p>
  
  <pre><code>bool Queue::push(ElementType newElement)
  {
     tail-&gt;next = new Node;
     if (tail-&gt;next == NULL)
     {
        return false;
     }
     tail-&gt;next-&gt;data.value = newElement;
     tail-&gt;next-&gt;next = NULL;
     tail = tail-&gt;next;
     return true;
  }
  
  ElementType Queue::pop()
  {
     Node *newNode;
     ElementType returnData;
     returnData = head-&gt;data.value;
     newNode = head;
     head = head-&gt;next;
     delete newNode;
     return returnData;
  }
  
  bool Queue::isEmpty()
  {
     if(head == NULL)
     {
         return true;
     }
     return false;
  }
  </code></pre>
  
  <p>why am I getting this error?
  4
  Assembly Line Simulator(9701) malloc: <strong>* error for object 0x1001000e0: pointer being freed was not allocated
  *</strong> set a breakpoint in malloc_error_break to debug</p>