我已经为地图/字典数据结构编写了一个模板类,并且不断收到这个奇怪的错误(ERROR LNK2019:unresolved external symbol)
代码:
AssArray.h:
#pragma once
template <class K,class D>
class AssArray
{
int _size;
int _position;
D* _data;
K* _key;
public:
AssArray(int);
~AssArray(void);
const D& operator [](K k) const;
D& operator [](K k);
};
AssArray.cpp:
#include "StdAfx.h"
#include "AssArray.h"
template <class K,class D>
AssArray<K,D>::AssArray(int size)
{
_size=size;
_data = new D[size];
_key = new K[size];
_position=0;
}
template <class K,class D>
AssArray<K,D>::~AssArray(void)
{
delete[] _data;
delete[] _key;
}
template <class K,class D>
const D& AssArray<K,D>::operator [](K k) const
{
//Get
for(int i=0;i<_position;i++)
if(_key[i]==d)
return _data[i];
return NULL;
}
template <class K,class D>
D& AssArray<K,D>::operator [](K k)
{
//Set
for(int i=0;i<_position;i++)
if(_key[i]==d)
return _data[i];
if(_position<_size-1)
{
_key[position]=d;
_position++;
return _data[_position];
}
else
{
//Implement error handling
}
}
错误是:
1
"Error 4 error LNK1120: 3 unresolved externals
C:\Users\*****\Documents\Visual Studio 2010\Projects\OOPLAB4NYARE\Debug
\OOPLAB4NYARE.exe 1 1 OOPLAB4NYARE"
2
Error 1 error LNK2019: unresolved external symbol "public: __thiscall
AssArray<char *,float>::~AssArray<char *,float>(void)" (??1?$AssArray@PADM@@QAE@XZ)
referenced in function _wmain C:\Users\*****\Documents\Visual Studio
2010\Projects\OOPLAB4NYARE\OOPLAB4NYARE\OOPLAB4NYARE.obj OOPLAB4NYARE
3
Error 3 error LNK2019: unresolved external symbol "public: __thiscall
AssArray<char *,float>::AssArray<char *,float>(int)" (??0?$AssArray@PADM@@QAE@H@Z)
referenced in function _wmain C:\Users\*****\Documents\Visual Studio
2010\Projects\OOPLAB4NYARE\OOPLAB4NYARE\OOPLAB4NYARE.obj OOPLAB4NYARE
4
Error 2 error LNK2019: unresolved external symbol "public: float &
__thiscall AssArray<char *,float>::operator[](char *)"
(??A?$AssArray@PADM@@QAEAAMPAD@Z) referenced in function _wmain C:\Users\Jonathan
\Documents\Visual Studio 2010\Projects\OOPLAB4NYARE\OOPLAB4NYARE\OOPLAB4NYARE.obj
OOPLAB4NYARE
我正在使用 Microsoft Visual Studio 2010 Ultimate。这很可能是我刚刚忽略的一些简单的事情。
我试图清理->重建,创建一个新项目并复制粘贴相关代码,以及试图找到一个解决方案,但我看到的那些非常多样化和模糊。