Hey guys so I am working on a Hash program in C++ for my class. I am using a template T class for my header file and when I try to call the class constructor from main it gives me a undeclared identifier and type 'int' unexpected error. Here is my HashTable.h file:
#pragma once
#include "Record.h"
#define MAXHASH 1000
#ifndef HASHTABLE_H
#define HASHTABLE_H
using namespace std;
template <class T> class HashTable
{
public:
HashTable();
~HashTable();
bool insert(int, T, int&);
bool remove(int);
bool find(int, T&);
float alpha();
private:
int key;
T value;
};
#endif
and here is my main:
#include "HashTable.h"
#include "stdafx.h"
#include <string>
#include <iostream>
using namespace std;
int main()
{
HashTable<int> *test = new HashTable<int>();
return 0;
}
Here's the constructor in the .cpp file as well:
#pragma once
#include "stdafx.h"
#include "HashTable.h"
#include "Record.h"
#define HASHTABLE_CPP
#ifndef HASTABLE_CPP
template <class T>
HashTable<T>::HashTable()
{
Record hashArray = new Record[MAXHASH];
for (int i = 0; i < MAXHASH; i++)
{
hashArray[i]->key = 0;
hashArray[i]->value = NULL;
}
}
The specific errors I am getting are:
Error C2062 type 'int' unexpected identifier Error C2065 'HashTable': undeclared identifier
Both the errors point to the call line in main.
It is difficult because I can't test my program until I can get this test hash to work. Any input on how to fix this issue would be awesome!