哈希映射错误:无法匹配'(const __gnu_cxx ::)

时间:2015-04-30 16:45:18

标签: c++ object compiler-errors hashmap

在编译我的hash_multimap之后,我得到了这个大的一段错误     在成员函数'size_t __gnu_cxx :: hashtable<

我从未见过这个巨大的错误,我实际上不确定如何修复此错误,因为它的大小异常。

任何建议为什么行:

p = map1.equal_range(searchKey);

导致这个异常长的错误?仅供参考 - 我删除了整个错误并删除了中间部分,因为一旦我粘贴在这里它就像一个页面长O.o

ERROR

/usr/include/c++/4.3/backward/hashtable.h: In member function ‘size_t
__gnu_cxx::hashtable<_Val, _Key, _HashFcn, _ExtractKey, _EqualKey,  
_Alloc>::_M_bkt_num_key(const _Key&, size_t) const [with _Val = 
std::pair<const std::basic_string<char, std::char_traits<char>, 
std::allocator<char> >, Map2*>, _Key = std::basic_string<char 

...

std::char_traits<char>, std::allocator<char> > >, _Alloc =     
std::allocator<Map2*>]’
hash_map2.cpp:55:   instantiated from here
/usr/include/c++/4.3/backward/hashtable.h:595: error: no match for call to  
‘(const __gnu_cxx::hash<std::basic_string<char, std::char_traits<char>,   
std::allocator<char> > >) (const std::basic_string<char, 
std::char_traits<char>, std::allocator<char> >&)’

Map.h文件

#ifndef MAP2_H
#define MAP2_H

#include <iostream>
#include <string>

using namespace std;

class Map2 {

public:
Map2(string data1, string data2, string data3, string data4, string data5);
string pop, keyword, user, desc, id;

string get_pop() {return pop;}
string get_key() {return keyword;}
string get_user() {return user;}
string get_desc() {return desc;}
string get_id() {return id;}

void call_Values(int i); 

};

Map2:: Map2(string data1, string data2, string data3, string data4, string data5) {
    pop = data1;
    keyword = data2;
    user = data3;
    desc = data4;
    id = data5;
}

void Map2:: call_Values(int i) {

    get_pop();
    get_key();
    get_user();
    get_desc();
    get_id();
}

#endif

hash_map2.cpp

#include <fstream>
#include <iostream>
#include "Map2.h"
#include <ext/hash_map>
#include <string>
#include <sstream>

using namespace std;
using __gnu_cxx::hash_multimap;

    int nav() {
            cout <<"Select from the following options : " << endl <<endl;
            cout <<"Search Tweets based on Keyword (Type 1) " <<endl;
            cout <<"End Program (Type 2)"<<endl<<endl;
            int key =0;
            cin >> key;
            return key;
    }

int main() {

int option = nav();

if (option == 1) {
    ifstream readFile("project4.csv");
    string tempPop, tempID, tempKey, tempUser, tempDesc;
    string tempRead;

    hash_multimap<string, Map2 *>map1;

    while (readFile != NULL){
        // sends to a temp variable
        readFile >> tempRead;

        for (int i =0; i<400; i++){
    //create new object each time
            Map2 *mapNode = new Map2(tempPop,tempID,tempKey,tempUser,tempDesc);
    //insert each time new object is made
    map1.insert(pair<string, Map2 *> (tempKey, mapNode));

        } //end for
    } //end while


//Navigation through multimap
    //first pointer is for first one and second to last hash table value
    pair<hash_multimap<string, Map2 *> :: const_iterator,
            hash_multimap<string, Map2 *> :: const_iterator> p;

    string searchKey = "";
    cout << "Please enter the keyword value exactly so we can search the"<< 
    "available tweets: " <<endl;

    cin >> searchKey;
    p = map1.equal_range(searchKey);







}

else

return 0;
}

1 个答案:

答案 0 :(得分:0)

问题是调用字符串进行搜索的事实。在调用equal_range函数内的值之前,需要将字符串转换为int。