我不断得到一个" lnk"错误。下面是.h文件。
template < class T, class KF >
class HashTbl
{
public:
HashTbl(int initTableSize);
~HashTbl();
void insert(const T &newDataItem) throw (bad_alloc);
bool remove(KF searchKey);
bool retrieve(KF searchKey, T &dataItem);
void clear();
bool isEmpty() const;
bool isFull() const;
void showStructure() const;
private:
int tableSize;
List<T> *dataTable;
};
这是.cpp文件:
template < class T, class KF >
HashTbl<T, KF>::HashTbl(int initTableSize) : tableSize(initTableSize)
{
dataTable = new List<T>[tableSize];
}
template < class T, class KF >
HashTbl<T, KF>:: ~HashTbl()
{
delete[] dataTable;
}
template < class T, class KF >
void HashTbl<T, KF>::insert(const T &newDataItem) throw (bad_alloc)
{
int index = 0;
index = newDataItem.hash(newDataItem.getKey()) % tableSize;
if (dataTable[index].isEmpty())
dataTable[index].insert(newDataItem);
else
{
dataTable[index].gotoBeginning();
do
{
if (dataTable[index].getCursor().getKey() == newDataItem.getKey())
{
dataTable[index].replace(newDataItem);
return;
}
} while (dataTable[index].gotoNext());
dataTable[index].insert(newDataItem);
}
}
template < class T, class KF >
bool HashTbl<T, KF>::remove(KF searchKey)
{
T temp;
int index = 0;
index = temp.hash(searchKey) % tableSize;
if (dataTable[index].isEmpty())
return false;
dataTable[index].gotoBeginning();
do
{
if (dataTable[index].getCursor().getKey() == searchKey)
{
dataTable[index].remove();
return true;
}
} while (dataTable[index].gotoNext());
return false;
}
template < class T, class KF >
bool HashTbl<T, KF>::retrieve(KF searchKey, T &dataItem)
{
// apply two hash functions:
// convert string (searchkey) to integer
// and use the remainder method (% tableSize) to get the index
int index = 0;
index = dataItem.hash(searchKey) % tableSize;
if (dataTable[index].isEmpty())
return false;
dataTable[index].gotoBeginning();
do
{
if (dataTable[index].getCursor().getKey() == searchKey)
{
dataItem = dataTable[index].getCursor();
return true;
}
} while (dataTable[index].gotoNext());
return false;
}
template < class T, class KF >
void HashTbl<T, KF>::clear()
{
for (int i = 0; i<tableSize; i++)
{
dataTable[i].clear();
}
}
template < class T, class KF >
bool HashTbl<T, KF>::isEmpty() const
{
for (int i = 0; i<tableSize; i++)
{
if (dataTable[i].isEmpty())
return false;
}
return true;
}
template < class T, class KF >
bool HashTbl<T, KF>::isFull() const
{
for (int i = 0; i<tableSize; i++)
{
if (dataTable[i].isFull())
return false;
}
return true;
}
template < class T, class KF >
void HashTbl<T, KF>::showStructure() const
{
cout << "The Hash Table has the following entries" << endl;
for (int i = 0; i<tableSize; i++)
{
cout<<i<< ": ";
if (dataTable[i].isEmpty())
cout << "_";
else
{
dataTable[i].gotoBeginning();
do
{
cout<<dataTable[i].getCursor().getKey() << " ";
} while (dataTable[i].gotoNext());
}
cout<<endl<<endl;
}
}
我不知道出了什么问题。我查看了这两个文件,看不到丢失的内容或不匹配的内容。我查看过去的一些帖子,他们指出声明和函数调用不匹配,我只是没有看到它。任何帮助,将不胜感激。
错误:
LNK2019未解析的外部符号&#34; public:__ thishisall HashTbl,class std :: allocator&gt; &gt; :: HashTbl,class std :: allocator&gt; &GT;(INT)&#34; (?? 0?$ HashTbl @ UPassword @@ V?$ basic_string @ DU?$ char_traits @ D @ std @@ V?$ allocator @ D @ 2 @@ std @@@@ QAE @ H @ Z)在函数中引用_main 1
LNK2019未解析的外部符号&#34; public:__ thishisall HashTbl,class std :: allocator&gt; &gt; ::〜HashTbl,class std :: allocator&gt; &GT;(无效)&#34; (?? 1?$ HashTbl @ UPassword @@ V?$ basic_string @ DU?$ char_traits @ D @ std @@ V?$ allocator @ D @ 2 @@ std @@@@ QAE @ XZ)在函数_main <中引用/ p>
LNK2019未解析的外部符号&#34; public:void __thiscall HashTbl,class std :: allocator&gt; &gt; :: insert(struct Password const&amp;)&#34; (?insert @?$ HashTbl @ UPassword @@ V?$ basic_string @ DU?$ char_traits @ D @ std @@ V?$ allocator @ D @ 2 @@ std @@@@ QAEXABUPassword @@@ Z)在函数中引用_main
LNK2019未解析的外部符号&#34; public:bool __thiscall HashTbl,class std :: allocator&gt; &gt; :: retrieve(class std :: basic_string,class std :: allocator&gt;,struct Password&amp;)&#34; (?检索@?$ @ HashTbl @@ UPassword V'$ @的basic_string杜?$ @ char_traits @ d @@性病V'$ @分配器@ d @@ 2性病@@@@ QAE_NV?$ @的basic_string杜?$ char_traits @ D @ std @@ V?$ allocator @ D @ 2 @@ std @@ AAUPassword @@@ Z)在函数_main
中引用LNK2019未解析的外部符号&#34; public:bool __thiscall HashTbl,class std :: allocator&gt; &gt; :: isFull(void)const&#34; (?isFull @?$ HashTbl @ UPassword @@ V?$ basic_string @ DU?$ char_traits @ D @ std @@ V?$ allocator @ D @ 2 @@ std @@@@ QBE_NXZ)在函数_main