what is wrong with this code?

Why isn't this code working? I am getting an error in main with the statement "hash armon". It is saying that reference to hash is ambiguous. What does it mean?

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
#include <iostream>

using namespace std;

class number
{
public:
	int number;
	bool marked=false;
};

class hash
{
	number array[27];

	int Hash(int key)
	{
		return key%27;
	}
	
public:
	
	void add(int Key)
	{
		int index=Hash(Key);

		while(array[index].marked==true)
		{
			index++;
		}

		array[index].number=Key;
		array[index].marked=true;
	}

	int find(int Key)
	{
		int index=Hash(Key);

		while(array[index].number!=Key&&index<27)
		{
			index++;
		}

		if(index==27)
		{
			return -1;
		}

		else
		{
			return array[index].number;
		}
	}
};

int main()
{
	hash armon;

	armon.add(4);

	cout<<armon.find(4);
}
Last edited on
This is why using namespace std; is bad. There is a std::hash function, and by bringing it into global scope you have no way to differentiate between the function and your class. Do not use using namespace std;

http://stackoverflow.com/q/1452721/1959975
i see, thanks a lot stranger!
Topic archived. No new replies allowed.