title: ERROR LNK2019:unresolved external symbol, c++
body: <p>I have written a template class, for a map/dictionary data structure, and keep getting this strange error (ERROR LNK2019:unresolved external symbol)</p>
  
  <p>Code:</p>
  
  <p>AssArray.h:</p>
  
  <pre><code>#pragma once   
  template &lt;class K,class D&gt;   
  class AssArray   
  {   
      int _size;   
      int _position;   
      D* _data;   
      K* _key;  
  
  public:    
       AssArray(int);
      ~AssArray(void);
  
      const D&amp; operator [](K k) const;
      D&amp; operator [](K k);
  };
  </code></pre>
  
  <p>AssArray.cpp: </p>
  
  <pre><code>#include "StdAfx.h"
  #include "AssArray.h"
  
  template &lt;class K,class D&gt;
  AssArray&lt;K,D&gt;::AssArray(int size)
  {
      _size=size;
      _data = new D[size];
      _key = new K[size];
      _position=0;
  }
  
  template &lt;class K,class D&gt;
  AssArray&lt;K,D&gt;::~AssArray(void)
  {
          delete[] _data;
      delete[] _key;
  }
  
  template &lt;class K,class D&gt;
  const D&amp; AssArray&lt;K,D&gt;::operator [](K k) const
  {
      //Get
      for(int i=0;i&lt;_position;i++)
          if(_key[i]==d)
              return _data[i];
      return NULL;
  }
  
  template &lt;class K,class D&gt;
  D&amp; AssArray&lt;K,D&gt;::operator [](K k)
  {
      //Set
      for(int i=0;i&lt;_position;i++)
          if(_key[i]==d)
              return _data[i];
  
      if(_position&lt;_size-1)
      {
          _key[position]=d;
          _position++;
          return _data[_position];
      }
      else
      {
          //Implement error handling
      }
  
  }
  </code></pre>
  
  <p>The errors are:<br>
  1</p>
  
  <pre><code>"Error  4   error LNK1120: 3 unresolved externals   
  C:\Users\*****\Documents\Visual Studio 2010\Projects\OOPLAB4NYARE\Debug
  \OOPLAB4NYARE.exe   1   1   OOPLAB4NYARE"
  </code></pre>
  
  <p>2</p>
  
  <pre><code>Error   1   error LNK2019: unresolved external symbol "public: __thiscall 
  AssArray&lt;char *,float&gt;::~AssArray&lt;char *,float&gt;(void)" (??1?$AssArray@PADM@@QAE@XZ)
  referenced in function _wmain   C:\Users\*****\Documents\Visual Studio
  2010\Projects\OOPLAB4NYARE\OOPLAB4NYARE\OOPLAB4NYARE.obj    OOPLAB4NYARE
  </code></pre>
  
  <p>3</p>
  
  <pre><code>Error   3   error LNK2019: unresolved external symbol "public: __thiscall
  AssArray&lt;char *,float&gt;::AssArray&lt;char *,float&gt;(int)" (??0?$AssArray@PADM@@QAE@H@Z) 
  referenced in function _wmain   C:\Users\*****\Documents\Visual Studio 
  2010\Projects\OOPLAB4NYARE\OOPLAB4NYARE\OOPLAB4NYARE.obj    OOPLAB4NYARE
  </code></pre>
  
  <p>4</p>
  
  <pre><code>Error   2   error LNK2019: unresolved external symbol "public: float &amp; 
  __thiscall AssArray&lt;char *,float&gt;::operator[](char *)" 
  (??A?$AssArray@PADM@@QAEAAMPAD@Z) referenced in function _wmain C:\Users\Jonathan
  \Documents\Visual Studio 2010\Projects\OOPLAB4NYARE\OOPLAB4NYARE\OOPLAB4NYARE.obj   
  OOPLAB4NYARE
  </code></pre>
  
  <p>I am using Microsoft visual studio 2010 Ultimate. It's most likely something easy I've just been overlooking.</p>
  
  <p>I have tried to clean->rebuild, created a new project and copy pasted the relevant code, as well as trying to find a solution, but the ones I've seen are pretty varied and vague.</p>