title: C++ - LNK2019 error unresolved external symbol [template class's constructor and destructor] referenced in function _main
body: <p>[[UPDATE]] -> If I #include "Queue.cpp" in my program.cpp, it works just fine. This shouldn't be necessary, right?</p>
  
  <p>Hey all -- I'm using Visual Studio 2010 and having trouble linking a quick-and-dirty Queue implementation. I started with an <em>empty</em> Win32 Console Application, and all files are present in the project. For verbosity, here's the complete code to duplicate my error. I realize some of the code may, in fact, be wrong. I haven't had a chance to test it yet because I haven't yet been able to link it.</p>
  
  <p>Queue.hpp</p>
  
  <pre><code>#ifndef ERROR_CODE
  #define ERROR_CODE
  enum Error_Code
  {
      Success,
      Underflow,
      Overflow
  };
  #endif // ERROR_CODE
  
  #ifndef QUEUE
  #define QUEUE
  template&lt;class T&gt;
  struct Queue_Node
  {
      T data;
      Queue_Node *next;
  
      Queue_Node()
      {
          next = NULL;
      }
      Queue_Node(T pData)
      {
          data = pData;
          next = NULL;
      }
      Queue_Node(T pData, Queue_Node *pNext)
      {
          data = pData;
          next = pNext;
      }
  };
  
  template&lt;class T&gt;
  class Queue
  {
  public:
      Queue();
      Error_Code Serve();
      Error_Code Append(T item);
      T Front();
      ~Queue();
  
  private:
      void Rescursive_Destroy(Queue_Node&lt;T&gt; *entry);
      Queue_Node&lt;T&gt; *front, *rear;
  };
  #endif // QUEUE
  </code></pre>
  
  <p>Queue.cpp</p>
  
  <pre><code>#include "Queue.hpp"
  
  template &lt;class T&gt;
  Queue&lt;T&gt;::Queue()
  {
      this-&gt;front = this-&gt;rear = NULL;
  }
  
  template&lt;class T&gt;
  Error_Code Queue&lt;T&gt;::Serve()
  {
      if(front == NULL)
          return Underflow;
  
      Queue_Node *temp = this-&gt;front;
      this-&gt;front = this-&gt;front-&gt;next;
      delete temp;
  }
  
  template&lt;class T&gt;
  Error_Code Queue&lt;T&gt;::Append(T item)
  {
      Queue_Node *temp = new Queue_Node(item);
      if(!temp)
          return Overflow;
  
      if(this-&gt;rear != NULL)
          this-&gt;rear-&gt;next = temp;
      this-&gt;rear = temp;
  
      return Success;
  }
  
  template&lt;class T&gt;
  T Queue&lt;T&gt;::Front()
  {
      if(this-&gt;front == NULL)
          return Underflow;
      return this-&gt;front-&gt;data;
  }
  
  template&lt;class T&gt;
  Queue&lt;T&gt;::~Queue()
  {
      this-&gt;Rescursive_Destroy(this-&gt;front);
  }
  
  template&lt;class T&gt;
  void Queue&lt;T&gt;::Rescursive_Destroy(Queue_Node&lt;T&gt; *entry)
  {
      if(entry != NULL)
      {
          this-&gt;Recursive_Destroy(entry-&gt;next);
          delete entry;
      }
  }
  </code></pre>
  
  <p>program.cpp</p>
  
  <pre><code>#include "Queue.hpp"
  
  int main()
  {
      Queue&lt;int&gt; steve;
      return 0;
  }
  </code></pre>
  
  <p>And the errors...</p>
  
  <pre><code>Error   1   error LNK2019: unresolved external symbol "public: __thiscall Queue&lt;int&gt;::~Queue&lt;int&gt;(void)" (??1?$Queue@H@@QAE@XZ) referenced in function _main    C:\[omitted]\Project2_2\Project2_2\program.obj  Project2_2
  Error   2   error LNK2019: unresolved external symbol "public: __thiscall Queue&lt;int&gt;::Queue&lt;int&gt;(void)" (??0?$Queue@H@@QAE@XZ) referenced in function _main C:\[omitted]\Project2_2\Project2_2\program.obj  Project2_2
  </code></pre>