I keep getting an "lnk" error. Below is the .h file.
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;
};
And this is the .cpp file:
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;
}
}
I don't know what is wrong. I have looked over both files and can't see what is missing or what doesn't match. I have looked at a few posts from the past and they point to a mismatch in the declaration and function call and I just don't see it. Any help would be appreciated.
Errors:
LNK2019 unresolved external symbol "public: __thiscall HashTbl,class std::allocator > >::HashTbl,class std::allocator > >(int)" (??0?$HashTbl@UPassword@@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@@QAE@H@Z) referenced in function _main 1
LNK2019 unresolved external symbol "public: __thiscall HashTbl,class std::allocator > >::~HashTbl,class std::allocator > >(void)" (??1?$HashTbl@UPassword@@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@@QAE@XZ) referenced in function _main
LNK2019 unresolved external symbol "public: void __thiscall HashTbl,class std::allocator > >::insert(struct Password const &)" (?insert@?$HashTbl@UPassword@@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@@QAEXABUPassword@@@Z) referenced in function _main
LNK2019 unresolved external symbol "public: bool __thiscall HashTbl,class std::allocator > >::retrieve(class std::basic_string,class std::allocator >,struct Password &)" (?retrieve@?$HashTbl@UPassword@@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@@QAE_NV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@AAUPassword@@@Z) referenced in function _main
LNK2019 unresolved external symbol "public: bool __thiscall HashTbl,class std::allocator > >::isFull(void)const " (?isFull@?$HashTbl@UPassword@@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@@QBE_NXZ) referenced in function _main