Hi I'm Josh and I'm new to these forums, and new to c++. I hope that I can get some great hints and help from the community. thank you in advance!
I'm trying to create and use a hashtable class that uses a linked list for separate chaining. I've completed the code but I can't declare the class without generating these errors:
Hashing error LNK2019: unresolved external symbol "public: __thiscall hashTable<class employeeType>::~hashTable<class employeeType>(void)" (??1?$hashTable@VemployeeType@@@@QAE@XZ) referenced in function _main
Hashing error LNK2019: unresolved external symbol "public: __thiscall hashTable<class employeeType>::hashTable<class employeeType>(class employeeType const &,int)" (??0?$hashTable@VemployeeType@@@@QAE@ABVemployeeType@@H@Z) referenced in function _main
This is the main program:
// Hashing.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
employeeType ITEM_NOT_FOUND("none",-100,-100);
hashTable<employeeType> test(ITEM_NOT_FOUND);
return 0;
}
here is the header for the hashtable class:
#pragma once
#include ".\linkedList.h"
#include <vector>
using namespace std;
template<class hashedObject>
class hashTable
{
public:
hashTable();
//constructor, requires ITEM_NOT_FOUND, and hashtable size
explicit hashTable(const hashedObject ¬Found, int size = 101);
hashTable(const hashTable &rhs)
: ITEM_NOT_FOUND(rhs.ITEM_NOT_FOUND),theLists(rhs.listArray) {}
//default destructor
~hashTable(void);
//empty the hashtable
void makeEmpty();
//insert an element into the hashtable
void insert(const hashedObject& insertObject);
//remove an item from the hash table
void remove(const hashedObject& deleteObject);
//retrieve an item from the table
const hashedObject& retrieve(const hashedObject &findObject);
const hashTable & operator=(const hashTable & rhs);
private:
vector<linkedListType<hashedObject> > listArray;
const hashedObject ITEM_NOT_FOUND;
};
//functions to hash the key
template<class hashedObject>
int hash(const hashedObject& key, int tableSize);
and here is the implementation for the hash table:
#include "StdAfx.h"
#include ".\hashtable.h"
//overload assignment operator
template <class hashedObject>
const hashTable<hashedObject> & hashTable<hashedObject>::operator=( const hashTable<hashedObject> & rhs )
{
if( this != &rhs )
listArray = rhs.listArray;
return *this;
}
template<class hashedObject>
hashTable<hashedObject>::hashTable()
{
}
//Constructor
template<class hashedObject>
hashTable<hashedObject>::hashTable(const hashedObject ¬Found, int size)
: ITEM_NOT_FOUND(notFound),listArray(nextPrime(size)) {}
//default destructor
template<class hashedObject>
hashTable<hashedObject>::~hashTable(void) {}
//delete all lists in each slot in the hash table
template<class hashedObject>
void hashTable<hashedObject>::makeEmpty()
{
for (int i = 0; i < listArray.size(); i++)
listArray[i].makeEmpty();
}
//delete an item from the hash table
template<class hashedObject>
void hashTable<hashedObject>::remove(const hashedObject &deleteObject)
{
int hashIndex = hash(deleteObject,listArray.size());
if (listArray[hashIndex].search(deleteObject))
listArray[hash(deleteObject,listArray.size())].deleteElement(deleteObject);
}
//search for an item and retrieve it, return ITEM_NOT_FOUND if not found
template<class hashedObject>
const hashedObject &hashTable<hashedObject>::retrieve(const hashedObject &findObject)
{
int hashIndex = hash(findObject,listArray.size());
if (listArray[hashIndex].search)
listArray[hashIndex].retrieve(findObject);
}
//insert an item into hashtable
template<class hashedObject>
void hashTable<hashedObject>::insert(const hashedObject &deleteObject)
{
linkedListType<hashedObject> & whichList = listArray[hash(deleteObject,listArray.size())];
if (!whichList.search(deleteObject))
whichList.insertFront(deleteObject);
}
I thought maybe there was a problem with my employeeType class, but when I tried declaring
hashTable<int> test(ITEM_NOT_FOUND);
it didn't work either... what did I do wrong? and more importantly, how can I avoid making this mistake again? thank you for your time!