title: Linked list with queue LNK2005 error
body: <p>Hello I wrote the following program (queue with linkedlist) but I have an error I can not figure out how to fix it I would be happy if you help me fix it.</p>
  
  <p>This is the code for my problem and i get 3 errors:</p>
  
  <blockquote>
    <p>Error   1   error LNK2005: "struct Node * rear" (?rear@@3PAUNode@@A) already defined in main.obj<br>
    Error   2   error LNK2005: "struct Node * front" (?front@@3PAUNode@@A) already defined in main.obj
    Error   3   error LNK1169: one or more multiply defined symbols found</p>
  </blockquote>
  
  <p>Code - </p>
  
  <p>queue.h</p>
  
  <pre><code>#ifndef _MYQUEUE_H
  #define _MYQUEUE_H
  #include &lt;iostream&gt;
  
  struct Node
  {
      int data;
      Node* next;
  } *rear, *front;
  
  
  void enqueue(int element);
  void dequeue();
  
  #endif
  </code></pre>
  
  <p>main</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include "myQueue.h"
  
  int main()
  {
      Node *rear;
      Node *front;
  
      enqueue(7);
      enqueue(4);
      enqueue(9);
  
      dequeue();
      dequeue();
      dequeue();
  
      system("pause");
  
      return 0;
  }
  </code></pre>
  
  <p>queue.cpp</p>
  
  <pre><code>#include "myQueue.h"
  
  void enqueue(int element)
  {
      Node* temp = new Node;
      temp-&gt;data = element;
      temp-&gt;next = NULL;
  
      if (front == NULL)
      {
          front = temp;
      }
      else
      {
          rear-&gt;next = temp;
      }
      rear = temp;
  }
  
  void dequeue()
  {
      Node* temp = new Node;
      if (front == NULL)
      {
          std::cout &lt;&lt; "No elements" &lt;&lt; std::endl;
      }
      else
      {
          temp = front;
          front = front-&gt;next;
          std::cout &lt;&lt; temp &lt;&lt; std::endl;
          delete temp;
      }
  }
  </code></pre>