我试图使用模板实现Hashtable,但出现错误,我的代码是:
#include <iostream>
#include <vector>
using namespace std;
template<class T>
class Hash {
int buckets;
vector<T> *bucket_array;
public:
Hash(int buck) { // always int.
this->buckets = buck;
bucket_array = new vector<T>[buck];
}
void insertHash(T value) {
int index = hashFunction(value);
if(find(bucket_array[index].begin(), bucket_array[index].end(), value) != bucket_array.end()) {
cout<<"Duplicates Cannot be stored !, Only Once.\n";
return;
}else
bucket_array[index].push_back(value);
}
这给出了错误-
error: member reference base type 'vector ' is not a structure or union
if(find(bucket_array[index].begin(), bucket_array[index].end(), value)
!= bucket_array.end()) {