terminate called after throwing an instance of 'long'

I am getting this error when I try to run my code. Since it doesn't give any lines that this error occur, I really don't know what to do.

Here is my code:
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
#include <iostream>
#include "Hash.h"
#include <algorithm>
#include <string>

Hash::Hash(unsigned int size) {
	arr = new Node[size];
	sz = size;
	cur_pt = 0;
}

unsigned int Hash::hasher(string key) {
	if (key.size() == 0) {
		throw(NULL);
	}
	unsigned int retval = 0;
	for (int i = 0; i < key.size(); ++i) {
		retval += key[i];
	}
	return retval % sz;
}

bool Hash::empty() {
	if (cur_pt == 0) {
		return 1;
	}
	return 0;
}

bool Hash::insert(string key, double value) {
	if (cur_pt == sz) {
		return 0;
	}
	int index = hasher(key);
	Node n;
	n.key = key;
	n.value = value;
	if (arr[index].key != "") {
		throw(NULL);
	}
	arr[index] = n;
	cur_pt++;
}

bool Hash::remove(string key) {
	int index = hasher(key);
	if (arr[index].key == key) {
		arr[index] = Node();
		cur_pt--;
		return 1;
	}
	return 0;
}

double Hash::find(string key) {
	for (int i = 0; i < sz; ++i) {
		if (key == arr[i].key) {
			return arr[i].value;
		}
	}
	return -1;
}
Last edited on
The only places you throw is on line 14 and 39 so it's probably one of those lines. A debugger can tell you exactly.
If you don't know about debuggers, you can insert a line like
cout << "line 14\n"; in that points;
Topic archived. No new replies allowed.