I want to build a hash table using a linked list
But there is a problem during compilation
I have tried using an array instead of a vector, but still the same result
Maybe it has something to do with the template?
I don't understand the sample code related to template
Here is some code that reproduces the problem, along with the error message
#include <iostream>
#include <vector>
using namespace std;
struct node
{
string key;
string value;
node* next;
};
class HashTable
{
private:
vector<node*> bucket;
long long int capacity;
public:
HashTable(long long int max_size = 100)
{
capacity = max_size;
bucket.reserve(capacity);
bucket.resize(capacity);
fill(bucket.begin(), bucket.end(), NULL);
}
};
Build started...
1>------ Build started: Project: C++ Test, Configuration: Debug x64 ------
1>C++ Test.cpp
1>E:\Other\Visual Studio\VC\Tools\MSVC\14.33.31629\include\xutility(4519,24): error C2440: '=': cannot convert from 'const _Ty' to 'node *'
1> with
1> [
1> _Ty=int
1> ]
1>E:\Other\Visual Studio\VC\Tools\MSVC\14.33.31629\include\xutility(4519,24): message : Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or parenthesized function-style cast
1>C:\Users\DaLaw2\source\repos\C++ Test\C++ Test.cpp(30): message : see reference to function template instantiation 'void std::fill<std::_Vector_iterator<std::_Vector_val<std::_Simple_types<_Ty>>>,int>(const _FwdIt,const _FwdIt,const int &)' being compiled
1> with
1> [
1> _Ty=node *,
1> _FwdIt=std::_Vector_iterator<std::_Vector_val<std::_Simple_types<node *>>>
1> ]
1>Done building project "C++ Test.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========