I need help figuring out these errors

Ok I started writing this program for a school project in Eclipse in windows and now shifting to vim in UNIX and I am getting a bunch of errors. I am currently trying to figure out the top two errors (And yes the funky characters are what I see).

Here is my stuff:

My makefile:

1
2
3
4
5
main: *.cpp *.h
        g++ -o LSL *.cpp

clean:
        rm -f *.o LSL*


Here are the errors when I run make:

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
unixserver:Lab3> make
g++ -o LSL *.cpp
ClosedHash.h:20: error: âHTâ has not been declared
ClosedHash.h:20: error: âposâ was not declared in this scope
ClosedHash.cpp: In destructor âvirtual ClosedHash::~ClosedHash()â:
ClosedHash.cpp:16: error: expected primary-expression before â;â token
ClosedHash.cpp: In function âbool insert(int, int)â:
ClosedHash.cpp:106: error: âgetKeyâ was not declared in this scope
ClosedHash.cpp:106: error: âhâ was not declared in this scope
ClosedHash.cpp:107: error: âEMPTYâ was not declared in this scope
ClosedHash.cpp:107: error: âHTâ was not declared in this scope
ClosedHash.cpp:107: error: âcheckHashâ was not declared in this scope
ClosedHash.cpp:108: error: âTOMBSTONEâ was not declared in this scope
ClosedHash.cpp:110: error: âprobeSeqâ was not declared in this scope
ClosedHash.cpp:110: error: âmaxSizeâ was not declared in this scope
ClosedHash.cpp:113: error: âHTâ was not declared in this scope
ClosedHash.cpp: In member function âvirtual bool ClosedHash::remove(int)â:
ClosedHash.cpp:126: error: âKâ was not declared in this scope
ClosedHash.cpp:127: error: âHTâ was not declared in this scope
ClosedHash.cpp:130: error: âMâ was not declared in this scope
ClosedHash.cpp:131: error: âHTâ was not declared in this scope
ClosedHash.cpp:132: error: âeâ was not declared in this scope
ClosedHash.cpp: At global scope:
ClosedHash.cpp:138: error: âHTâ has not been declared
ClosedHash.cpp:138: error: âposâ was not declared in this scope
ClosedHash.cpp:157: error: non-member function âint count()â cannot have cv-qualifier
ClosedHash.cpp: In function âint count()â:
ClosedHash.cpp:158: error: invalid conversion from âint (*)()constâ to âintâ
ClosedHash.cpp: At global scope:
ClosedHash.cpp:162: error: non-member function âfloat alpha()â cannot have cv-qualifier
ClosedHash.cpp: In function âfloat alpha()â:
ClosedHash.cpp:163: error: âmaxSizeâ was not declared in this scope
ClosedHash.cpp: At global scope:
ClosedHash.cpp:169: error: non-member function âbool full()â cannot have cv-qualifier
ClosedHash.h:20: error: âHTâ has not been declared
ClosedHash.h:20: error: âposâ was not declared in this scope
main.cpp: In function âint main()â:
main.cpp:172: error: no matching function for call to âClosedHash::ClosedHash(int)â
ClosedHash.h:16: note: candidates are: ClosedHash::ClosedHash()
ClosedHash.h:13: note:                 ClosedHash::ClosedHash(const ClosedHash&)
make: *** [main] Error 1
unixserver:Lab3> 
[/code]

Here are my code files:

Hash.h:

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
#ifndef __Hash_h__
#define __Hash_h__

class Hash {

protected: // Protected since children need access to these static properties.

  static const int EMPTY = -1;
  static const int TOMBSTONE = -2;

 public:
  // Insert an integer into the hash.  Return true if successful,
  // false if there are no more slots in the hash, or the integer
  // is already found.  Store the number of collisions in the
  // variable 'collisions'.
  virtual bool insert(int newValue, int &collisions) = 0;

  // Find an integer value in the hash.  Return true if found,
  // false if not.  Store the number of probes in the variable
  // 'probes'.
  virtual bool find(int searchValue, int &probes) const = 0;

  // Delete an integer from the hash.  Return true if successful,
  // false if unsuccessful.
  virtual bool remove(int delValue) = 0;

  // Return the number of items currently in the hash.
  virtual int count() const = 0;

  // Return the current alpha value of the hash.
  virtual float alpha() const = 0;
  
  // Returns true if the hash is full, otherwise false.
  // NB: This is only meaningful in a closed hash table.
  virtual bool full() const = 0;
};

#endif 


ClosedHash.h:

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
#ifndef _CLOSEDHASH_H
#define	_CLOSEDHASH_H

#include "Hash.h"

class ClosedHash : public Hash {

public:
    ClosedHash();
    bool insert(int newValueId, int &collisions);
    bool find(int searchValue, int &probes) const;
    bool remove(int delValue);
    bool checkHash(int EMPTY, HT[pos]);
    bool checkKey();
    bool probeSeq();
    int count() const;
    float alpha() const;
    bool full() const;
    int getKey(int ID);

    virtual ~ClosedHash();
    unsigned int h(int key) const;
    unsigned int h2(int key) const;

private:
    const int maxSize;
};

#endif	/* _CLOSEDHASH_H */ 


ClosedHash.cpp:

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
#include "ClosedHash.h"

void ClosedHash(int maxSize) {
    int hashTable[maxSize]; // I think this is my problem - commented out and Changed to HT[masSize] next line
    //int HT[maxSize];
}

ClosedHash::~ClosedHash() {
	delete[] ClosedHash;
}

unsigned int ClosedHash::h(int key) const {
  unsigned int hash = 0;      // The hash value starts at 0
  unsigned int keyarr = key;  // A copy of the key

  // We will treat the key (an integer) as an array of 4
  // unsigned characters
  unsigned char *keyptr = (unsigned char *) &keyarr;

  // Mix each 8-bit character into the hash
  for (int i = 0; i < (sizeof(int)); i++) {

    // This is the combining step:
    hash += keyptr[i];

    // This is the mixing step:
    hash += (hash << 10);
    hash ^= (hash >> 6);
  }

  // After all the bits of the key have been mixed in,
  // ensure that they are properly distributed throughout
  // the final hash value:
  hash += (hash << 3);
  hash ^= (hash >> 11);
  hash += (hash << 15);

  // This last line assumes the you have a data member
  // or constant in class ClosedHash called maxSize.  This
  // is the value M (the number of buckets in the hash).  This
  // can be a private data element or constant.
  return hash % maxSize;
}

//  ****
//  For comments, see h(), above!
//  Also see the comments near the end of h2().
//  ****

unsigned int ClosedHash::h2(int key) const {
  unsigned int hash = 0;
  unsigned int keyarr = key;
  unsigned char *keyptr = (unsigned char *) &keyarr;

  for (int i = 0; i < sizeof(int); i++) {
    hash += keyptr[i];
    hash += (hash << 9);
    hash ^= (hash >> 5);
  }
  hash += (hash << 3);
  hash ^= (hash >> 11);
  hash += (hash << 15);

  // The following code ensures that the value of h2(k) will be
  // odd, which should be coprime with the size of the closed
  // hash (32,768 == 2^15).
  return (((hash * 2) + 1) % maxSize);
}

// Insert ID into hash table HT

bool insert(int ID, int collisions) {
    int home; // Home position for ID
    int pos = home = h(getKey(ID)); // Init probe sequence
    for (int i = 1; (!(checkHash(EMPTY, HT[pos])) &&
            !(checkHash(TOMBSTONE, HT[pos]))); i++) {
	    // TODO Shouldn't I replace getKey(ID) with just ID?
        pos = (home + probeSeq(getKey(ID), i)) % maxSize; // Follow probes | function p is the probe sequence
        if (checkHash(ID, HT[pos])) return false; // Duplicate
    }
    HT[pos] = ID; // Insert ID
    return true;
}

bool ClosedHash::find(int searchValue, int &probes) const {

}

// Search for and delete the record with Key K

bool ClosedHash::remove(int delValue) {
    int home; // Home position for K
    // Initial posit on probe sequence
    int pos = home = h(K);
    for (int i = 1; !checkKey(K, HT[pos]) &&
            !checkHash(EMPTY, HT[pos]); i++)
        // Next on probe sequence
        pos = (home + probeSeq(K, i)) % M;
    if (checkKey(K, HT[pos])) { // Found it
        e = HT[pos];
        HT[pos] = TOMBSTONE; // Delete it
        return true;
    } else return false; // K not in hash table
}

bool checkHash(int EMPTY, HT[pos]){
	// TODO
}

bool checkKey() {
	// TODO
}

bool probeSeq() {
	// TODO
}


// TODO fix up the below 4 functions...
int getKey(int ID) {
    return ID; //return the key of the requested ID;
}

// Return the number of items currently in the hash.
int count() const {
    return count;
}

// Return the current alpha value of the hash.
float alpha() const {
    return count / maxSize;

}

  // Returns true if the hash is full, otherwise false.
  // NB: This is only meaningful in a closed hash table.
bool full() const {
    //if hash is full return true else return false;
    //
    // if hash.size() == maxSize return true; // How do I size of hash??
    // else return false; // false == hash is not full
}
Last edited on
If we look at the first error reported:

ClosedHash.h:20: error: HT has not been declared

Then go to line 13 of your ClosedHash.h which appears to correspond with the line indicated in the error message:

bool checkHash(int EMPTY, HT[pos]);

What is HT? What is pos? They aren't defined in ClosedHash.h or Hash.h which it includes. Did you bother checking the source against the error messages?
Topic archived. No new replies allowed.