将struct的对象插入到哈希表C ++中

时间:2014-03-15 22:13:01

标签: c++ struct hashtable

我目前正在处理涉及哈希表的项目。我已经将文本文件读入符号结构的向量中,现在我必须将这些结构(对象,实际上)插入到哈希表中。我被赋予了一个特定的插入功能,但是,我似乎无法让它工作。我已经包含了下面的插入函数以及我的Driver.cpp文件,其中包含读取文件中的结构向量以及我将其插入哈希表的尝试。

如果我出错了,我将不胜感激。

#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <string>
#include <time.h> 
#include <unistd.h>
#include "SeparateChaining.h" 

using namespace std;

struct Symbol
{
    int type;
    string name;
};

size_t hash(const string & key); //declaration of hashing function

int main()
{
    /************ VARS ***************/
    string line;
    int line_count;
    int table_size;
    int increment;

    /************ Vector of Symbols ***************/
    vector<Symbol> symbols;

    /************ HashTable of Symbols ***************/
    HashTable<Symbol> hashtable; //precomputed to have 101 elements --> probably will change this to accomodate table size.

    cout << "Opening file..." << endl;
    usleep(2000000);

    ifstream file;
    file.open("symbols.txt");

    if(!file)
    {
        cout << "System failed to open file.";
    }
    else
    {
        cout << "File successfully opened" << endl;
    }

    cout << "Please enter the table size for the Hash Table. (NOTE: It MUST be a prime number.)" << endl;
    cin >> table_size;

    for(Symbol temp; file >> temp.name >> temp.type;)
    {
        symbols.push_back(temp);
        increment++;
    }
    //Just to test and see if its loading it correctly...
    for(int i = 0; i < symbols.size(); i++)
    {
        cout << symbols[i].name << endl;
        cout << symbols[i].type << endl;
    }
    for(int j = 0; j < symbols.size(); j++)
    {
        hashtable.insert(symbols); // Messing up here !!!!!!!!!!!!!
    }
    //cout << ::hash("hi") << endl;
}

size_t hash( const string & key )
{
    size_t hashVal = 0;

    for( char ch : key )
        hashVal = 37 * hashVal + ch;

    return hashVal;
}

在SeparateChaining.h中插入函数:

bool insert( const HashedObj & x )
    {
        auto & whichList = theLists[ myhash( x ) ];
        if( find( begin( whichList ), end( whichList ), x ) != end( whichList) )
            return false;
        whichList.push_back( x );

            // Rehash; see Section 5.5
        if( ++currentSize > theLists.size( ) )
            rehash( );

        return true;
    }

    bool insert( HashedObj && x )
    {
        auto & whichList = theLists[ myhash( x ) ];      
        if( find( begin( whichList ), end( whichList ), x ) != end( whichList ) )
            return false;
        whichList.push_back( std::move( x ) );

            // Rehash; see Section 5.5
        if( ++currentSize > theLists.size( ) )
            rehash( );

        return true;
    }

当hashtable.insert(符号)完成时出错:

    Driver.cpp: In function 'int main()':
    Driver.cpp:65:27: error: no matching function for call to 'HashTable<Symbol>::insert(std::vector<Symbol>&)'
    Driver.cpp:65:27: note: candidates are:
    In file included from Driver.cpp:8:0:
    SeparateChaining.h:44:10: note: bool HashTable<HashedObj>::insert(const HashedObj&) [with HashedObj = Symbol]
    SeparateChaining.h:44:10: note:   no known conversion for argument 1 from 'std::vector<Symbol>' to 'const Symbol&'
    SeparateChaining.h:58:10: note: bool HashTable<HashedObj>::insert(HashedObj&&) [with HashedObj = Symbol]
    SeparateChaining.h:58:10: note:   no known conversion for argument 1 from 'std::vector<Symbol>' to 'Symbol&&'

在通过向量递增后作为hashtable.insert(symbols [j])完成时出错:

In file included from /opt/local/include/gcc47/c++/bits/basic_string.h:3032:0,
                             from /opt/local/include/gcc47/c++/string:54,
                             from /opt/local/include/gcc47/c++/bits/locale_classes.h:42,
                             from /opt/local/include/gcc47/c++/bits/ios_base.h:43,
                             from /opt/local/include/gcc47/c++/ios:43,
                             from /opt/local/include/gcc47/c++/ostream:40,
                             from /opt/local/include/gcc47/c++/iostream:40,
                             from Driver.cpp:1:
            /opt/local/include/gcc47/c++/bits/functional_hash.h: In instantiation of 'struct std::hash<Symbol>':
            SeparateChaining.h:107:32:   required from 'size_t HashTable<HashedObj>::myhash(const HashedObj&) const [with HashedObj = Symbol; size_t = long unsigned int]'
            SeparateChaining.h:46:50:   required from 'bool HashTable<HashedObj>::insert(const HashedObj&) [with HashedObj = Symbol]'
            Driver.cpp:65:30:   required from here
            /opt/local/include/gcc47/c++/bits/functional_hash.h:60:7: error: static assertion failed: std::hash is not specialized for this type
            In file included from /opt/local/include/gcc47/c++/algorithm:63:0,
                             from SeparateChaining.h:8,
                             from Driver.cpp:8:
            /opt/local/include/gcc47/c++/bits/stl_algo.h: In instantiation of '_InputIterator std::__find(_InputIterator, _InputIterator, const _Tp&, std::input_iterator_tag) [with _InputIterator = std::_List_iterator<Symbol>; _Tp = Symbol]':
            /opt/local/include/gcc47/c++/bits/stl_algo.h:4466:45:   required from '_IIter std::find(_IIter, _IIter, const _Tp&) [with _IIter = std::_List_iterator<Symbol>; _Tp = Symbol]'
            SeparateChaining.h:47:9:   required from 'bool HashTable<HashedObj>::insert(const HashedObj&) [with HashedObj = Symbol]'
            Driver.cpp:65:30:   required from here
            /opt/local/include/gcc47/c++/bits/stl_algo.h:135:7: error: no match for 'operator==' in '__first.std::_List_iterator<_Tp>::operator*<Symbol>() == __val'
            /opt/local/include/gcc47/c++/bits/stl_algo.h:135:7: note: candidates are:
            In file included from /opt/local/include/gcc47/c++/bits/stl_algo.h:68:0,
                             from /opt/local/include/gcc47/c++/algorithm:63,
                             from SeparateChaining.h:8,
                             from Driver.cpp:8:
            /opt/local/include/gcc47/c++/functional:2382:5: note: template<class _Res, class ... _Args> bool std::operator==(std::nullptr_t, const std::function<_Res(_ArgTypes ...)>&)
            /opt/local/include/gcc47/c++/functional:2382:5: note:   template argument deduction/substitution failed:
            In file included from /opt/local/include/gcc47/c++/algorithm:63:0,
                             from SeparateChaining.h:8,
                             from Driver.cpp:8:
            /opt/local/include/gcc47/c++/bits/stl_algo.h:135:7: note:   cannot convert '__first.std::_List_iterator<_Tp>::operator*<Symbol>()' (type 'Symbol') to type 'std::nullptr_t'
            In file included from /opt/local/include/gcc47/c++/bits/stl_algo.h:68:0,
                             from /opt/local/include/gcc47/c++/algorithm:63,
                             from SeparateChaining.h:8,
                             from Driver.cpp:8:
            /opt/local/include/gcc47/c++/functional:2376:5: note: template<class _Res, class ... _Args> bool std::operator==(const std::function<_Res(_ArgTypes ...)>&, std::nullptr_t)
            /opt/local/include/gcc47/c++/functional:2376:5: note:   template argument deduction/substitution failed:
            In file included from /opt/local/include/gcc47/c++/algorithm:63:0,
                             from SeparateChaining.h:8,
                             from Driver.cpp:8:
            /opt/local/include/gcc47/c++/bits/stl_algo.h:135:7: note:   'Symbol' is not derived from 'const std::function<_Res(_ArgTypes ...)>'
            In file included from /opt/local/include/gcc47/c++/functional:56:0,
                             from /opt/local/include/gcc47/c++/bits/stl_algo.h:68,
                             from /opt/local/include/gcc47/c++/algorithm:63,
                             from SeparateChaining.h:8,
                             from Driver.cpp:8:
            /opt/local/include/gcc47/c++/tuple:797:5: note: template<class ... _TElements, class ... _UElements> bool std::operator==(const std::tuple<_Elements ...>&, const std::tuple<_Elements ...>&)
            /opt/local/include/gcc47/c++/tuple:797:5: note:   template argument deduction/substitution failed:
            In file included from /opt/local/include/gcc47/c++/algorithm:63:0,
                             from SeparateChaining.h:8,
                             from Driver.cpp:8:
            /opt/local/include/gcc47/c++/bits/stl_algo.h:135:7: note:   'Symbol' is not derived from 'const std::tuple<_Elements ...>'
            In file included from /opt/local/include/gcc47/c++/random:51:0,
                             from /opt/local/include/gcc47/c++/bits/stl_algo.h:67,
                             from /opt/local/include/gcc47/c++/algorithm:63,
                             from SeparateChaining.h:8,
                             from Driver.cpp:8:
            /opt/local/include/gcc47/c++/bits/random.tcc:1713:5: note: template<class _RealType1> bool std::operator==(const std::normal_distribution<_RealType>&, const std::normal_distribution<_RealType>&)
            /opt/local/include/gcc47/c++/bits/random.tcc:1713:5: note:   template argument deduction/substitution failed:
            In file included from /opt/local/include/gcc47/c++/algorithm:63:0,
                             from SeparateChaining.h:8,
                             from Driver.cpp:8:
            /opt/local/include/gcc47/c++/bits/stl_algo.h:135:7: note:   'Symbol' is not derived from 'const std::normal_distribution<_RealType>'
            In file included from /opt/local/include/gcc47/c++/list:64:0,
                             from SeparateChaining.h:6,
                             from Driver.cpp:8:
            /opt/local/include/gcc47/c++/bits/stl_list.h:1574:5: note: template<class _Tp, class _Alloc> bool std::operator==(const std::list<_Tp, _Alloc>&, const std::list<_Tp, _Alloc>&)
            /opt/local/include/gcc47/c++/bits/stl_list.h:1574:5: note:   template argument deduction/substitution failed:
            In file included from /opt/local/include/gcc47/c++/algorithm:63:0,
                             from SeparateChaining.h:8,
                             from Driver.cpp:8:
            /opt/local/include/gcc47/c++/bits/stl_algo.h:135:7: note:   'Symbol' is not derived from 'const std::list<_Tp, _Alloc>'
            In file included from /opt/local/include/gcc47/c++/list:64:0,
                             from SeparateChaining.h:6,
                             from Driver.cpp:8:
            /opt/local/include/gcc47/c++/bits/stl_list.h:277:5: note: template<class _Val> bool std::operator==(const std::_List_iterator<_Tp>&, const std::_List_const_iterator<_Val>&)
            /opt/local/include/gcc47/c++/bits/stl_list.h:277:5: note:   template argument deduction/substitution failed:
            In file included from /opt/local/include/gcc47/c++/algorithm:63:0,
                             from SeparateChaining.h:8,
                             from Driver.cpp:8:
            /opt/local/include/gcc47/c++/bits/stl_algo.h:135:7: note:   'Symbol' is not derived from 'const std::_List_iterator<_Tp>'
            In file included from /opt/local/include/gcc47/c++/vector:65:0,
                             from Driver.cpp:4:
            /opt/local/include/gcc47/c++/bits/stl_vector.h:1370:5: note: template<class _Tp, class _Alloc> bool std::operator==(const std::vector<_Tp, _Alloc>&, const std::vector<_Tp, _Alloc>&)
            /opt/local/include/gcc47/c++/bits/stl_vector.h:1370:5: note:   template argument deduction/substitution failed:
            In file included from /opt/local/include/gcc47/c++/algorithm:63:0,
                             from SeparateChaining.h:8,
                             from Driver.cpp:8:
            /opt/local/include/gcc47/c++/bits/stl_algo.h:135:7: note:   'Symbol' is not derived from 'const std::vector<_Tp, _Alloc>'
            In file included from /opt/local/include/gcc47/c++/bits/locale_facets.h:50:0,
                             from /opt/local/include/gcc47/c++/bits/basic_ios.h:39,
                             from /opt/local/include/gcc47/c++/ios:45,
                             from /opt/local/include/gcc47/c++/ostream:40,
                             from /opt/local/include/gcc47/c++/iostream:40,
                             from Driver.cpp:1:
            /opt/local/include/gcc47/c++/bits/streambuf_iterator.h:206:5: note: template<class _CharT, class _Traits> bool std::operator==(const std::istreambuf_iterator<_CharT, _Traits>&, const std::istreambuf_iterator<_CharT, _Traits>&)
            /opt/local/include/gcc47/c++/bits/streambuf_iterator.h:206:5: note:   template argument deduction/substitution failed:
            In file included from /opt/local/include/gcc47/c++/algorithm:63:0,
                             from SeparateChaining.h:8,
                             from Driver.cpp:8:
            /opt/local/include/gcc47/c++/bits/stl_algo.h:135:7: note:   'Symbol' is not derived from 'const std::istreambuf_iterator<_CharT, _Traits>'
            In file included from /opt/local/include/gcc47/c++/string:54:0,
                             from /opt/local/include/gcc47/c++/bits/locale_classes.h:42,
                             from /opt/local/include/gcc47/c++/bits/ios_base.h:43,
                             from /opt/local/include/gcc47/c++/ios:43,
                             from /opt/local/include/gcc47/c++/ostream:40,
                             from /opt/local/include/gcc47/c++/iostream:40,
                             from Driver.cpp:1:
            /opt/local/include/gcc47/c++/bits/basic_string.h:2516:5: note: template<class _CharT, class _Traits, class _Alloc> bool std::operator==(const std::basic_string<_CharT, _Traits, _Alloc>&, const _CharT*)
            /opt/local/include/gcc47/c++/bits/basic_string.h:2516:5: note:   template argument deduction/substitution failed:
            In file included from /opt/local/include/gcc47/c++/algorithm:63:0,
                             from SeparateChaining.h:8,
                             from Driver.cpp:8:
            /opt/local/include/gcc47/c++/bits/stl_algo.h:135:7: note:   'Symbol' is not derived from 'const std::basic_string<_CharT, _Traits, _Alloc>'
            In file included from /opt/local/include/gcc47/c++/string:54:0,
                             from /opt/local/include/gcc47/c++/bits/locale_classes.h:42,
                             from /opt/local/include/gcc47/c++/bits/ios_base.h:43,
                             from /opt/local/include/gcc47/c++/ios:43,
                             from /opt/local/include/gcc47/c++/ostream:40,
                             from /opt/local/include/gcc47/c++/iostream:40,
                             from Driver.cpp:1:
            /opt/local/include/gcc47/c++/bits/basic_string.h:2504:5: note: template<class _CharT, class _Traits, class _Alloc> bool std::operator==(const _CharT*, const std::basic_string<_CharT, _Traits, _Alloc>&)
            /opt/local/include/gcc47/c++/bits/basic_string.h:2504:5: note:   template argument deduction/substitution failed:
            In file included from /opt/local/include/gcc47/c++/algorithm:63:0,
                             from SeparateChaining.h:8,
                             from Driver.cpp:8:
            /opt/local/include/gcc47/c++/bits/stl_algo.h:135:7: note:   mismatched types 'const _CharT*' and 'Symbol'
            In file included from /opt/local/include/gcc47/c++/string:54:0,
                             from /opt/local/include/gcc47/c++/bits/locale_classes.h:42,
                             from /opt/local/include/gcc47/c++/bits/ios_base.h:43,
                             from /opt/local/include/gcc47/c++/ios:43,
                             from /opt/local/include/gcc47/c++/ostream:40,
                             from /opt/local/include/gcc47/c++/iostream:40,
                             from Driver.cpp:1:
            /opt/local/include/gcc47/c++/bits/basic_string.h:2490:5: note: template<class _CharT> typename __gnu_cxx::__enable_if<std::__is_char<_Tp>::__value, bool>::__type std::operator==(const std::basic_string<_CharT>&, const std::basic_string<_CharT>&)
            /opt/local/include/gcc47/c++/bits/basic_string.h:2490:5: note:   template argument deduction/substitution failed:
            In file included from /opt/local/include/gcc47/c++/algorithm:63:0,
                             from SeparateChaining.h:8,
                             from Driver.cpp:8:
            /opt/local/include/gcc47/c++/bits/stl_algo.h:135:7: note:   'Symbol' is not derived from 'const std::basic_string<_CharT>'
            In file included from /opt/local/include/gcc47/c++/string:54:0,
                             from /opt/local/include/gcc47/c++/bits/locale_classes.h:42,
                             from /opt/local/include/gcc47/c++/bits/ios_base.h:43,
                             from /opt/local/include/gcc47/c++/ios:43,
                             from /opt/local/include/gcc47/c++/ostream:40,
                             from /opt/local/include/gcc47/c++/iostream:40,
                             from Driver.cpp:1:
            /opt/local/include/gcc47/c++/bits/basic_string.h:2483:5: note: template<class _CharT, class _Traits, class _Alloc> bool std::operator==(const std::basic_string<_CharT, _Traits, _Alloc>&, const std::basic_string<_CharT, _Traits, _Alloc>&)
            /opt/local/include/gcc47/c++/bits/basic_string.h:2483:5: note:   template argument deduction/substitution failed:
            In file included from /opt/local/include/gcc47/c++/algorithm:63:0,
                             from SeparateChaining.h:8,
                             from Driver.cpp:8:
            /opt/local/include/gcc47/c++/bits/stl_algo.h:135:7: note:   'Symbol' is not derived from 'const std::basic_string<_CharT, _Traits, _Alloc>'
            In file included from /opt/local/include/gcc47/c++/string:43:0,
                             from /opt/local/include/gcc47/c++/bits/locale_classes.h:42,
                             from /opt/local/include/gcc47/c++/bits/ios_base.h:43,
                             from /opt/local/include/gcc47/c++/ios:43,
                             from /opt/local/include/gcc47/c++/ostream:40,
                             from /opt/local/include/gcc47/c++/iostream:40,
                             from Driver.cpp:1:
            /opt/local/include/gcc47/c++/bits/allocator.h:124:5: note: template<class _Tp> bool std::operator==(const std::allocator<_CharT>&, const std::allocator<_CharT>&)
            /opt/local/include/gcc47/c++/bits/allocator.h:124:5: note:   template argument deduction/substitution failed:
            In file included from /opt/local/include/gcc47/c++/algorithm:63:0,
                             from SeparateChaining.h:8,
                             from Driver.cpp:8:
            /opt/local/include/gcc47/c++/bits/stl_algo.h:135:7: note:   'Symbol' is not derived from 'const std::allocator<_CharT>'
            In file included from /opt/local/include/gcc47/c++/string:43:0,
                             from /opt/local/include/gcc47/c++/bits/locale_classes.h:42,
                             from /opt/local/include/gcc47/c++/bits/ios_base.h:43,
                             from /opt/local/include/gcc47/c++/ios:43,
                             from /opt/local/include/gcc47/c++/ostream:40,
                             from /opt/local/include/gcc47/c++/iostream:40,
                             from Driver.cpp:1:
            /opt/local/include/gcc47/c++/bits/allocator.h:119:5: note: template<class _T1, class _T2> bool std::operator==(const std::allocator<_CharT>&, const std::allocator<_T2>&)
            /opt/local/include/gcc47/c++/bits/allocator.h:119:5: note:   template argument deduction/substitution failed:
            In file included from /opt/local/include/gcc47/c++/algorithm:63:0,
                             from SeparateChaining.h:8,
                             from Driver.cpp:8:
            /opt/local/include/gcc47/c++/bits/stl_algo.h:135:7: note:   'Symbol' is not derived from 'const std::allocator<_CharT>'
            In file included from /opt/local/include/gcc47/c++/bits/stl_algobase.h:68:0,
                             from /opt/local/include/gcc47/c++/bits/char_traits.h:41,
                             from /opt/local/include/gcc47/c++/ios:41,
                             from /opt/local/include/gcc47/c++/ostream:40,
                             from /opt/local/include/gcc47/c++/iostream:40,
                             from Driver.cpp:1:
            /opt/local/include/gcc47/c++/bits/stl_iterator.h:1039:5: note: template<class _Iterator> bool std::operator==(const std::move_iterator<_Iterator>&, const std::move_iterator<_Iterator>&)
            /opt/local/include/gcc47/c++/bits/stl_iterator.h:1039:5: note:   template argument deduction/substitution failed:
            In file included from /opt/local/include/gcc47/c++/algorithm:63:0,
                             from SeparateChaining.h:8,
                             from Driver.cpp:8:
            /opt/local/include/gcc47/c++/bits/stl_algo.h:135:7: note:   'Symbol' is not derived from 'const std::move_iterator<_Iterator>'
            In file included from /opt/local/include/gcc47/c++/bits/stl_algobase.h:68:0,
                             from /opt/local/include/gcc47/c++/bits/char_traits.h:41,
                             from /opt/local/include/gcc47/c++/ios:41,
                             from /opt/local/include/gcc47/c++/ostream:40,
                             from /opt/local/include/gcc47/c++/iostream:40,
                             from Driver.cpp:1:
            /opt/local/include/gcc47/c++/bits/stl_iterator.h:1033:5: note: template<class _IteratorL, class _IteratorR> bool std::operator==(const std::move_iterator<_Iterator>&, const std::move_iterator<_IteratorR>&)
            /opt/local/include/gcc47/c++/bits/stl_iterator.h:1033:5: note:   template argument deduction/substitution failed:
            In file included from /opt/local/include/gcc47/c++/algorithm:63:0,
                             from SeparateChaining.h:8,
                             from Driver.cpp:8:
            /opt/local/include/gcc47/c++/bits/stl_algo.h:135:7: note:   'Symbol' is not derived from 'const std::move_iterator<_Iterator>'
            In file included from /opt/local/include/gcc47/c++/bits/stl_algobase.h:68:0,
                             from /opt/local/include/gcc47/c++/bits/char_traits.h:41,
                             from /opt/local/include/gcc47/c++/ios:41,
                             from /opt/local/include/gcc47/c++/ostream:40,
                             from /opt/local/include/gcc47/c++/iostream:40,
                             from Driver.cpp:1:
            /opt/local/include/gcc47/c++/bits/stl_iterator.h:343:5: note: template<class _IteratorL, class _IteratorR> bool std::operator==(const std::reverse_iterator<_Iterator>&, const std::reverse_iterator<_IteratorR>&)
            /opt/local/include/gcc47/c++/bits/stl_iterator.h:343:5: note:   template argument deduction/substitution failed:
            In file included from /opt/local/include/gcc47/c++/algorithm:63:0,
                             from SeparateChaining.h:8,
                             from Driver.cpp:8:
            /opt/local/include/gcc47/c++/bits/stl_algo.h:135:7: note:   'Symbol' is not derived from 'const std::reverse_iterator<_Iterator>'
            In file included from /opt/local/include/gcc47/c++/bits/stl_algobase.h:68:0,
                             from /opt/local/include/gcc47/c++/bits/char_traits.h:41,
                             from /opt/local/include/gcc47/c++/ios:41,
                             from /opt/local/include/gcc47/c++/ostream:40,
                             from /opt/local/include/gcc47/c++/iostream:40,
                             from Driver.cpp:1:
            /opt/local/include/gcc47/c++/bits/stl_iterator.h:293:5: note: template<class _Iterator> bool std::operator==(const std::reverse_iterator<_Iterator>&, const std::reverse_iterator<_Iterator>&)
            /opt/local/include/gcc47/c++/bits/stl_iterator.h:293:5: note:   template argument deduction/substitution failed:
            In file included from /opt/local/include/gcc47/c++/algorithm:63:0,
                             from SeparateChaining.h:8,
                             from Driver.cpp:8:
            /opt/local/include/gcc47/c++/bits/stl_algo.h:135:7: note:   'Symbol' is not derived from 'const std::reverse_iterator<_Iterator>'
            In file included from /opt/local/include/gcc47/c++/bits/stl_algobase.h:65:0,
                             from /opt/local/include/gcc47/c++/bits/char_traits.h:41,
                             from /opt/local/include/gcc47/c++/ios:41,
                             from /opt/local/include/gcc47/c++/ostream:40,
                             from /opt/local/include/gcc47/c++/iostream:40,
                             from Driver.cpp:1:
            /opt/local/include/gcc47/c++/bits/stl_pair.h:206:5: note: template<class _T1, class _T2> constexpr bool std::operator==(const std::pair<_T1, _T2>&, const std::pair<_T1, _T2>&)
            /opt/local/include/gcc47/c++/bits/stl_pair.h:206:5: note:   template argument deduction/substitution failed:
            In file included from /opt/local/include/gcc47/c++/algorithm:63:0,
                             from SeparateChaining.h:8,
                             from Driver.cpp:8:
            /opt/local/include/gcc47/c++/bits/stl_algo.h:135:7: note:   'Symbol' is not derived from 'const std::pair<_T1, _T2>'
            In file included from /opt/local/include/gcc47/c++/iosfwd:42:0,
                             from /opt/local/include/gcc47/c++/ios:39,
                             from /opt/local/include/gcc47/c++/ostream:40,
                             from /opt/local/include/gcc47/c++/iostream:40,
                             from Driver.cpp:1:
            /opt/local/include/gcc47/c++/bits/postypes.h:218:5: note: template<class _StateT> bool std::operator==(const std::fpos<_StateT>&, const std::fpos<_StateT>&)
            /opt/local/include/gcc47/c++/bits/postypes.h:218:5: note:   template argument deduction/substitution failed:
            In file included from /opt/local/include/gcc47/c++/algorithm:63:0,
                             from SeparateChaining.h:8,
                             from Driver.cpp:8:
            /opt/local/include/gcc47/c++/bits/stl_algo.h:135:7: note:   'Symbol' is not derived from 'const std::fpos<_StateT>'

1 个答案:

答案 0 :(得分:0)

尝试

hashtable.insert(symbols[j]);

另外,您不能使用incrementline_counttable_size,只需设置它们即可。

说明: 您尝试插入整个矢量,而不是其元素,因此数据类型不匹配。通过使用数组表示法,您可以获取要插入的实际元素。

为什么你甚至使用向量而不是直接将符号插入哈希表?