-2
Я пытаюсь реализовать вектор связанных списков, но я сталкиваюсь с проблемой при реализации функции insert.C++ HashTable Вставить функцию
Определение класса: реализация
#include <vector>
#include <list>
#include <string>
using namespace std;
class HashTable {
public:
HashTable(int size);
unsigned int hash(string key);
void insert(string x);
private:
vector<list<string> >* table;
Класс:
#include "hashTable.h"
#include <string>
#include <list>
#include <vector>
using namespace std;
HashTable::HashTable(int size) {
table = new vector<list<string> >(size);
}
HashTable::insert(string x){
unsigned int index = hash(x); //left out the hash function for brevity
table[index].push_back(x);
}
Я получаю ошибку:
hashTable.cpp:38:26: error: no viable conversion from 'string' (aka
'basic_string<char, char_traits<char>, allocator<char> >') to
'const value_type' (aka 'const
std::__1::list<std::__1::basic_string<char>,
std::__1::allocator<std::__1::basic_string<char> > >')
table[index].push_back(x);
Что такое 'a' здесь, которое вставлено push_back? –
Не 'новый вектор'. Для этого не существует никакой причины. Сделайте вектор членом класса напрямую. –
включите определение вашего класса, пожалуйста. – kfsone