c++ - HashMap 错误: no match for call to ‘(const __gnu_cxx::

标签 c++ object compiler-errors hashmap

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

我从未见过如此大的错误,而且由于大小异常,我实际上不确定如何解决此错误。

任何建议为什么行:

p = map1.equal_range(searchKey);

导致此异常长错误?仅供引用-我削减了整个错误并删除了中间部分,因为一旦我将其粘贴到此处,它就像一页纸一样长

错误
/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;
}

最佳答案

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

关于c++ - HashMap 错误: no match for call to ‘(const __gnu_cxx::,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29973386/

相关文章:

linux - 构建 Linux Kernel 4.18 时出现编译时错误

C++ 奇怪的 char* 参数问题(不兼容的类型)

c++ - Windows & C++ : extern & __declspec(dllimport)

c++ - 如何请求操作系统发送邮件?

c++ - 测量网络延迟

PHP 等效于 ASP.NET 应用程序/缓存对象

java - println() 对象帮助语句。我的教授想要这个输出吗?

javascript - 将数组转换为嵌套对象

c++ - 如何防止对迭代器实例的悬挂引用

java - 如何修复 intellij 中的 NoClassDefFoundError 错误?