I'm trying to create a hash table with a vector inside a vector made of a struct. v[1].push_back(value);
it's giving me an error:
error C2664: 'void std::vector<node,std::allocator<node>>::push_back(_Ty &&)': cannot convert argument 1 from 'int' to 'const _Ty &'
with
[
_Ty=node
]
note: Reason: cannot convert from 'int' to 'const _Ty'
with
[
_Ty=node
]
note: No constructor could take the source type, or constructor overload resolution was ambiguous
Here is my code: struct node { int data;
node() {
data = 0;
}
};
class hashmap {
public:
vector<vector<struct node>> v;
vector<struct node> n;
hashmap() {
for (int i = 0; i < 5; i++) {
v.push_back(n);
}
}
void insert(int key, int value) {
int index = Hashfunction(key);
v[1].push_back(value);
}
int Hashfunction(int key) {
int index = key % v.size();
return index;
}
};