Hashing problem with overloaded operator

I'm just now learning hashing and it's giving me some trouble. I've got a StateData Class that is to be hashed by the hashT class. I've overloaded the != operator once as a friend function and another time as a function of the StateData class but I keep getting the same error '!=' : no operator found which takes a left-hand operand of type 'StateData'. I'm at a complete loss on this and would appreciate any help I can get. Thanks!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
#ifndef H_STATEDATA
#define H_STATEDATA

class StateData
{
public:
	StateData();
	StateData(string, string, int, int);
	void setStateInfo(string, string, int, int);
	string getName();
	string getCapitol();
	int getYearAdmit();
	int getOrder();
	StateData getStateData();

	friend bool operator<(StateData &, StateData &);
	friend bool operator>(StateData &, StateData &);
//	friend bool operator!=(StateData &, StateData &);
	bool operator!=(StateData &);
	friend bool operator==(StateData &, StateData &);
	friend ostream &operator <<(ostream&, StateData);
	friend istream &operator>>(istream &, StateData &);

private:
	string name;
	string capitol;
	int yearAdmit;
	int order;

};
#endif

#include<iostream>
#include<string>
using namespace std;
#include "stateData.h";

	StateData::StateData()
	{
		name = " ";
		capitol = " ";
		yearAdmit = 0;
		order = 0;
	}

	StateData::StateData(string n, string c, int y, int o)
	{
		name = n;
		capitol = c;
		yearAdmit = y;
		order = o;
	}

	void StateData::setStateInfo(string n, string c, int y, int o)
	{
		name = n;
		capitol = c;
		yearAdmit = y;
		order = o;
	}

	string StateData::getName()
	{        return name;          }

	string StateData::getCapitol()
		{        return capitol;          }

	int StateData::getYearAdmit()
		{        return yearAdmit;          }

	int StateData::getOrder()
		{        return order;          }

	//StateData StateData::getStateData()
	//	{        return this;          }

	bool operator<(StateData &right, StateData &left)
	{          return (right.getName() < left.getName());     }

	bool operator>(StateData &right, StateData &left)
	{          return (right.getName() > left.getName());     }

	bool operator==(StateData &right, StateData &left)
	{          return (right.getName() == left.getName());     }

	//bool operator!=(StateData &right, StateData &left)
	//{          return (right.getName() != left.getName());     }

	bool StateData::operator!=(StateData &left)
	{          return (this->name != left.name);     }


	ostream &operator <<(ostream& out, StateData &a)
	{
		out << "State name: " << a.getName() << endl;
		out << "State capitol: " << a.getCapitol() << endl;
		out << "Year of admittance: " << a.getYearAdmit() << endl;
		out << "Order of admittance: " << a.getOrder() << endl;
		return out;
	}

	istream &operator>>(istream &in, StateData &a)
	{
		string n, c;
		int y, o;
		cout << "Enter State name: ";
		getline(cin, n);
		cout << "Enter State capitol: ";
		getline(cin, c);
		cout << "Enter year of admittance: ";
		cin >> y;
		cout << "Enter order of admittance: ";
		cin >> o;
		a.setStateInfo(n, c, y, o);
		return in;
	}

#ifndef H_Htable
#define H_Htable

#include <iostream>
#include <cassert>

using namespace std;

template<class elemType>
class hashT
{
private:
    elemType *HTable;		//pointer to the hash table
    int *indexStatusList;	//pointer to the array indicating
							//the status of a position in the
							//hash table
    int length;				//number of items in the hash table
    int HTSize;				//maximum size of the hash table
};
//public function causing the error

template <class elemType>
void hashT<elemType>::insert(int hashIndex, const elemType& rec)
{
	int pCount;
	int inc;

	pCount = 0;
	inc = 1;

	while(indexStatusList[hashIndex] == 1
		  && HTable[hashIndex] != rec   //error occurs here
		  && pCount < HTSize / 2)
	{
		cout <<"inc = " << inc << endl;
		pCount++;
		hashIndex = (hashIndex + inc ) % HTSize;
		cout << "new hashIndex = " << hashIndex << endl;
		inc = inc + 2;
	}


	if(indexStatusList[hashIndex] != 1)
	{
		HTable[hashIndex] = rec;
		cout << "HTable["<< hashIndex <<"]" <<" = " << rec << endl;
		indexStatusList[hashIndex] = 1;
		length++;
	}
	else
		if(HTable[hashIndex] == rec)
			cerr<<"Error: No duplicates are allowed"<<endl;
		else
			cerr<<"Error: The table is full. "
			    <<"Unable to resolve the collision"<<endl;
}

#include <iostream>
#include <fstream>
#include <string>
#include "hashT.h"
#include "stateData.h"

using namespace std;

int hashFunc(string name, int size);

int main()
{
	hashT<StateData> HashTable(50);
	int size = 50;

	ifstream infile;

	infile.open("states.txt");
	if(!infile)
	{
		cout << "Error reading states file.\n";
		exit(1);
	}

	char ch;
	int year, order, key;
	string state, capitol;
	bool found;

	getline(infile, state);

	while(infile)
	{
		StateData temp;
		getline(infile, capitol);
		infile >> year;
		infile >> order;
		temp.setStateInfo(state, capitol, year, order);
		infile.get(ch);
		key = hashFunc(state, size);
		HashTable.insert(key, temp);

		getline(infile, state);
	}

	HashTable.print();

	//cout<<"Enter item to be deleted: ";
	//cin>>num;
	//cout<<endl;

	infile.close();
	system("pause");
	return 0;

}

int hashFunc(string name, int size)
{
	int i, sum, len;
	i= 0;
	sum = 0;
	len = name.length();
	for (int k=0; k < 15 - len; k++)
		name = name + ' ';
	for (int k = 0; k < 5; k++)
	{
		sum = sum + static_cast<int>(name[i]) * 128 * 128
			+ static_cast<int>(name[i+1]) * 128
			+ static_cast<int>(name[i+2]);
		i = i+3;
	}
	return sum % size;
}
Last edited on
Bumping this for help. I've been looking at this for two days.
Topic archived. No new replies allowed.