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 
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 

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 

	count = 0; 

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) 

	if(i == buckets[index].end()) 
		return make_pair(iterator(this,index,--(buckets[index].end())),true);
		return make_pair(iterator(this,index, i),false); 

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


int spellCheck::size() 
	return count; 


8 Years
Discussion Span
Last Post by StuXYZ

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
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 topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.