#I am having trouble compiling my code for HashTables

4 messages · Page 1 of 1 (latest)

autumn capeBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.

rare lodge
#

These are the errors im getting after i create my hashtable object in main.cpp i've been stuck on it for a while now. Does anyon2 know how to fix it? Here is my code: hashtable.h ```
#ifndef HASHTABLE_H
#define HASHTABLE_H

#include <string>
#include <iostream>

using std::cout;
using std::endl;
using std::string;

#define HASHTABLESIZE 15

#include "linkedlist.h"
#include "data.h"

class Hashtable{

private: 
int hash(int); // hash function, returns index of array to add value to
int count;

public:

Hashtable();
~Hashtable();

bool insertEntry(int, string*);
string getData(int, string&);
bool removeEntry(int);
int getCount();
void printTable();

};

#endif

hashtable.cpp

/*

  • This is a simple Hash Table using separate chaining
    */

#include "hashtable.h"

// declare hash varaible

LinkedList hashTable[HASHTABLESIZE];

Hashtable::Hashtable(){
count = 0;
}

Hashtable::~Hashtable() {
// nothing to do here
}

//hash private function

int Hashtable::hash(int id){
return id % HASHTABLESIZE;
}

//public functions

bool Hashtable::insertEntry(int id, string* data){
bool success = false;
if (id > 0) {
success = hashTable[hash(id)].addNode(id, data);
if (success) {
count++;
}
}
return success;
}

string Hashtable::getData(int id, string& data){
bool success = false;
if (id > 0) {
Data* collectData = new Data;
success = hashTable[hash(id)].getNode(id, collectData);
data = collectData->data;
}
return data;

}

bool Hashtable::removeEntry(int id){
bool success = false;
if (id > 0) {
success = hashTable[hash(id)].deleteNode(id);
if (success) {
count--;
}
}
return success;
}

int Hashtable::getCount(){
return count;
}

void Hashtable::printTable(){
for (int i = 0; i < HASHTABLESIZE; i++) {
cout << "Index " << i << ": ";
hashTable[i].printList();
}
}

main.cpp object

Hashtable* ht = new Hashtable();

#

!solved