I'm getting an error code C2753 -- 'HashTable: Partial Specialization Cannot Match Argument List for Primary Template -- when I try to build my project.
My HashTable.h file:
#pragma once //should prevent error C2953..... 'HashTable': class template has already been defined. https://stackoverflow.com/questions/10157416/error-class-template-has-already-been-defined
#include <string>
#include <iostream>
#include <iomanip>
#include "Record.h"
using namespace std;
/*Create a closed hash HashTable using Double Hashing & Templates and does not allow duplicates.*/
template <class T>
class HashTable<T> {
private:
int numItems;
int hashSize;
Record<T> *hashArray;
int hashOne(int) const;
int hashTwo(int) const;
public:
/*TEMPLATE*/
HashTable();
~HashTable();
bool insert(int, T, int&);
bool remove(int);
bool find(int, T&);
float alpha();
int getNumItems();
int getSize();
bool print();
/*Source: Partial Code for Overriding print method from StackOverflow.com*/
ostream& print(ostream& os) const {
os << "-----------------------------------------------------------------------" << endl;
os << "Hash Table Slot #|" << setw(20) << "Key and Value" << setw(12) << "" << endl;
os << "-----------------------------------------------------------------------" << endl;
for (int i = 0; i < hashSize; i++)
{
os << setw(10) << i << setw(8) << "|";
if (hashArray[i].isEmpty())
os << setw(16) << hashArray[i] << setw(14) << "" << endl;
else if (hashArray[i].isTombstone())
os << setw(20) << hashArray[i] << setw(12) << "" << endl;
else
os << setw(12) << hashArray[i] << endl;
}
os << "-----------------------------------------------------------------------" << endl;
return os;
}
}; //End of HashTable Class
/*Constructor of the HashTable.
Initializes the size to 1000 and numItems to 0.
Loop to fill hashArray with empty records.*/
template <class T>
HashTable<T>::HashTable() {
this->hashSize = 1000;
this->numItems = 0;
hashArray = new Record<T>[hashSize];
for (int i = 0; i < hashSize; i++) {
hashArray[i] = Record<T>();
}
} //end of Constructor
/*Deconstructor for HashTable. Deletes hashArray.*/
template <class T>
HashTable<T>::~HashTable() {
delete[] hashArray;
} //end of Deconstructor
/*Insert a new key/value pair into the HashTable, duplicates not allowed.
If added return true, return the numver of collisions in int& collisions,and increment numItems.
Otherwise return false.*/
template<class T>
bool HashTable<T>::insert(int key, T value, int& collisions) {
if (numItems >= hashSize) {
cout << "HashArray FULL!" << endl;
return false;
}
if (hashArray[hashOne(key)].isNormal()) {
int loc = 0;
if (hashArray[(hashOne(key) + loc) % hashSize].getKey() == key) {
return false;
}
while (hashArray[(hashOne(key) + loc) % hashSize].isNormal()) {
collisions++;
loc = loc + hashTwo(key);
if (hashArray[(hashOne(key) + loc) % hashSize].getKey() == key) {
return false;
}
}
hashArray[(hashOne(key) + loc) % hashSize] = Record<T>(key, value);
numItems++;
return true;
}
else {
hashArray[hashOne(key)] = Record<T>(key, value);
numItems++;
return true;
}
return false;
} //end insert method
//...other methods go here...//
//hashOne & hashTwo functions are my last two functions, if that matters.
My .cpp file is really just bare bones, but here it is:
#include "stdafx.h"
#include "HashTable.h"
int main() {
return 0;
}
I am using Visual Studio 2015 & have already looked Here, here, here, and here trying to find a solution, along with numerous other sources from Google and cplusplus.com, but none of these have solved my problem.
Any help or advice will be greatly appreciated!