Trying to create a hash table class that is basically like a spell checker. The header file seems all good but the implementation i'm having issues with. Primarily the insert function keeps vomiting on me when i try to compile. Basically complaining about my iterators being wrong??? Anyways, here's my code. Any help would be appreciated!

//spellcheck.h header file 
#include <iostream> 
#include "d_hashf.h"
#include <vector> 
#include <list> 

using namespace std; 

template<typename keyType, typename T, typename Hfunc> 
class spellCheck 
{ 
public: 
spellCheck(); //default constructor 

class iterator;
typedef pair<keyType, T> EntryType;

bool empty(); // tells whether table is empty 

int size(); //how many items in the hash table 

iterator find(const string& key); //points to item if in table 

pair<iterator, bool> insert(EntryType& entry) ; //inserts item into table 

private: 
static const int LENGTH = 1373;  //length of buckets 
int count; //amount of items in hash table 
vector<list<string>> buckets; //vector of lists of strings as hash table 
hFstring hash_fcn; 


} ;
//Implementation file for spellcheck.h 
 

#include "spellcheck.h" 
#include <fstream> 

 
string s = ""; //default value for hashfunction 

spellCheck<string,string,hFstring>::spellCheck() 
{ 
	buckets.resize(LENGTH); 
	count = 0; 
	hash_fcn(s); 
} 

pair<iterator, bool> spellCheck<string,string,hFstring>::insert(EntryType& entry) 
{ 
	int index = hash_fcn(entry.first) % buckets.size(); 

	list<EntryType>::iterator i = buckets[index].begin(); 
	while(i != buckets[index].end() && i->first != entry.first) 
		++i; 

	if(i == buckets[index].end()) 
	{ 
		buckets[index].push_back(EntryType(entry)); 
		count++; 
		return make_pair(iterator(this,index,--(buckets[index].end())),true);
	} 
	else 
		return make_pair(iterator(this,index, i),false); 
} 

bool spellCheck::empty()  
{ 
	if count == 0;  
		return true; 
	else 
		return false; 

} 

int spellCheck::size() 
{ 
	return count; 

} 


}

In future please add the compiler error messages (well the first few).

you seem to define your own iterators in spellcheck. That is going to cause problem LATER.

pair<iterator,bool> requiires a complete type of YOUR iterator
that is only pre-declared with the line class iterator; Another problem is that list<EntryType>::iterator i = buckets[index].begin(); make i an iterator of type list<EntryType>::iterotor
BUT
buckets[index] is a list of type string but entryType is a pair.

Additionally.. pair<iterator, bool> spellCheck<string,string,hFstring>::insert(EntryType& entry) needs a template<> in-front of it since it is a specialization.
Also there is not generic, so why bother with a template class???

Sorry for the rant. Basically, you should start again. Write it WITHOUT templates and then convert. It will be much easier.

Additionally, don't use using namespace std; It is not making your life easier just adding to the confusion. You need to wri te std::list etc BUT then you are clear when you are using your own and when you are using the stl.

This article has been dead for over six months. Start a new discussion instead.