Author Topic: [solved] C++ no match for call to hasher ???  (Read 5207 times)

0 Members and 1 Guest are viewing this topic.

Offline DiTBhoTopic starter

  • Super Contributor
  • ***
  • Posts: 4182
  • Country: gb
[solved] C++ no match for call to hasher ???
« on: December 27, 2020, 11:40:17 am »
I don't know anything about C++, I am a C programmer, but I need to compile a tool that is written in C++, and I am stopped with this error:

map.cpp
Code: [Select]
/usr/lib/gcc-v10.2.0/include/g++-v10/backward/hashtable.h:604:23:
error: no match for call to ‘(const hasher {aka const __gnu_cxx::hash<long long unsigned int>}) (const key_type&)’
  604 |       { return _M_hash(__key) % __n; }
      |                ~~~~~~~^~~~~~~

which can be reproduced by the following testing-example:

Code: [Select]
#include <fstream>
#include <iostream>
#include "map.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;
}

map.h
Code: [Select]
#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


Anyone has an idea? Workaround? or any doc-suggestion to look at?
« Last Edit: December 27, 2020, 03:37:06 pm by DiTBho »
The opposite of courage is not cowardice, it is conformity. Even a dead fish can go with the flow
 

Offline DiTBhoTopic starter

  • Super Contributor
  • ***
  • Posts: 4182
  • Country: gb
Re: C++ no match for call to hasher ???
« Reply #1 on: December 27, 2020, 11:56:56 am »
Code: [Select]
CXXFLAGS=-g -std=c++11

I have this in the Makefile.
The opposite of courage is not cowardice, it is conformity. Even a dead fish can go with the flow
 

Offline DiTBhoTopic starter

  • Super Contributor
  • ***
  • Posts: 4182
  • Country: gb
Re: C++ no match for call to hasher ???
« Reply #2 on: December 27, 2020, 11:59:29 am »
This is the line where g++ traps error

/usr/lib/gcc-v10.2.0/include/g++-v10/backward/hashtable.h:604:23:
Code: [Select]
      size_type
      _M_bkt_num_key(const key_type& __key, std::size_t __n) const
      { return _M_hash(__key) % __n; }
The opposite of courage is not cowardice, it is conformity. Even a dead fish can go with the flow
 

Offline janoc

  • Super Contributor
  • ***
  • Posts: 3851
  • Country: de
Re: C++ no match for call to hasher ???
« Reply #3 on: December 27, 2020, 01:22:27 pm »
When asking stuff like this always post the entire set of error messages. When I have tried to compile your code, there was a lot more going on, this is important to see.

E.g. this doesn't bother you?

Code: [Select]
hash.cpp: In function ‘int main()’:
hash.cpp:34:25: error: no match for ‘operator!=’ (operand types are ‘std::ifstream’ {aka ‘std::basic_ifstream<char>’} and ‘long int’)
         while (readFile != NULL)
                         ^
hash.cpp:34:25: note: candidate: ‘operator!=(int, long int)’ <built-in>

That's literally the first error I get when trying to compile your code. You can't compare ifstream with a pointer (and at that note - don't use NULL but nullptr in C++). Without fixing that there is no point dealing with the rest of errors because one failure in compiling the templates will propagate and cause a lot of other errors as a consequence.


* Don't use ext/hash_map - that's old, deprecated and non-standard. If you want a unordered hash table, use unordered_map instead, otherwise normal map. See e.g.:

http://www.cplusplus.com/reference/unordered_map/unordered_multimap/
 
* Don't name your headers the same as the system headers map.h is also a system header and this a good way to shoot yourself in the foot because yours could get included before the system one.
« Last Edit: December 27, 2020, 01:31:13 pm by janoc »
 
The following users thanked this post: DiTBho

Offline DiTBhoTopic starter

  • Super Contributor
  • ***
  • Posts: 4182
  • Country: gb
Re: C++ no match for call to hasher ???
« Reply #4 on: December 27, 2020, 01:45:08 pm »
* Don't use ext/hash_map - that's old, deprecated and non-standard

I am trying to compile a big project written in C++ of which I am not the author, so I can't "don't use this" because I cannot change what someone did use, and I have ZERO skills with C++ to rewrite things from scratch, so I can only try to fix something in order to get the project compiled.
The opposite of courage is not cowardice, it is conformity. Even a dead fish can go with the flow
 

Online magic

  • Super Contributor
  • ***
  • Posts: 7033
  • Country: pl
Re: C++ no match for call to hasher ???
« Reply #5 on: December 27, 2020, 01:48:57 pm »
I would go as far as suggesting the contrary: only post the first error message ;)
G++ tries to continue as far as it can despite errors, and as problems with the code accumulate and cause further issues, the errors it prints get increasingly bizarre and misleading.
 

Offline DiTBhoTopic starter

  • Super Contributor
  • ***
  • Posts: 4182
  • Country: gb
Re: C++ no match for call to hasher ???
« Reply #6 on: December 27, 2020, 01:52:56 pm »
When asking stuff like this always post the entire set of error messages. When I have tried to compile your code, there was a lot more going on, this is important to see.

Ok, so forget the posted code above; when I try to compile the big project, the first error I encounter is:

Code: [Select]
/usr/lib/gcc/9.3.0/include/g++-v9/backward/hashtable.h:609:31: error: no match for call to ‘(const hasher {aka const __gnu_cxx::hash<long long unsigned int>}) (const key_type&)’
  609 |       { return _M_hash(__key) % __n; }
ac_hltrace.cpp:409:13: warning: ‘bool print_dwarf_function(Dwfl_Module*, Dwarf_Addr, LineInfo*)’ defined but not used [-Wunused-function]
  409 | static bool print_dwarf_function (Dwfl_Module *mod, Dwarf_Addr addr, LineInfo* lineInfo)
      |             ^~~~~~~~~~~~~~~~~~~~


/usr/lib/gcc/9.3.0/include/g++-v9/backward/hashtable.h:609
Code: [Select]
607:     size_type
608:      _M_bkt_num_key(const key_type& __key, size_t __n) const
609:      { return _M_hash(__key) % __n; }

Note I am using g++ v9.3.0 now.
The same happens with g++ v4.7
The opposite of courage is not cowardice, it is conformity. Even a dead fish can go with the flow
 

Online magic

  • Super Contributor
  • ***
  • Posts: 7033
  • Country: pl
Re: C++ no match for call to hasher ???
« Reply #7 on: December 27, 2020, 02:08:57 pm »
See if it helps to replace the obsolete ext/hash_map with unordered map:

replace <ext/hash_map> with <unordered_map>
remove using namespace __gnu_cxx::blahabla
replace all occurences of hash_(multi)map with unordered_(multi)map

As for the other problem, old C++ standards had a conversion from ifstream to void*, newer have a conversion from ifstream to bool. So simply remove '!= NULL' and you should get the behavior the author intended, I think.
 
The following users thanked this post: DiTBho

Offline DiTBhoTopic starter

  • Super Contributor
  • ***
  • Posts: 4182
  • Country: gb
Re: C++ no match for call to hasher ???
« Reply #8 on: December 27, 2020, 03:36:40 pm »
Digging deeper I found the project was compiled with gcc-v4.7, but I cannot compile such old Gcc compiler for several reasons, so I applied your suggestions, and the project is now compiled ready to work

Thank you! You saved my day :D
The opposite of courage is not cowardice, it is conformity. Even a dead fish can go with the flow
 

Offline janoc

  • Super Contributor
  • ***
  • Posts: 3851
  • Country: de
Re: C++ no match for call to hasher ???
« Reply #9 on: December 27, 2020, 07:29:31 pm »
* Don't use ext/hash_map - that's old, deprecated and non-standard

I am trying to compile a big project written in C++ of which I am not the author, so I can't "don't use this" because I cannot change what someone did use, and I have ZERO skills with C++ to rewrite things from scratch, so I can only try to fix something in order to get the project compiled.

Well, what you have posted is certainly no "big project". Either post what you are actually trying to build and not some random code you have cobbled together and which cannot compile due to evident syntax errors or you have a strange idea about what consists a large C++ project.

Digging deeper I found the project was compiled with gcc-v4.7, but I cannot compile such old Gcc compiler for several reasons, so I applied your suggestions, and the project is now compiled ready to work

Thank you! You saved my day :D

Good, glad to see you have managed to fix that.
« Last Edit: December 27, 2020, 07:32:01 pm by janoc »
 

Offline DiTBhoTopic starter

  • Super Contributor
  • ***
  • Posts: 4182
  • Country: gb
Re: [solved] C++ no match for call to hasher ???
« Reply #10 on: December 27, 2020, 09:48:35 pm »
[..] you have a strange idea about what consists a large C++ project.

The above posted code got found Googling, and comes from StackOverflow, but it's confused and doesn't solve anything. I found it Googling about the strange error I got compiling a project of 2.000 C++ files.

Aren't 2.000 files "enough" for you to define it as "large C++ project" ?  :D
The opposite of courage is not cowardice, it is conformity. Even a dead fish can go with the flow
 

Offline DiTBhoTopic starter

  • Super Contributor
  • ***
  • Posts: 4182
  • Country: gb
Re: [solved] C++ no match for call to hasher ???
« Reply #11 on: December 27, 2020, 10:06:08 pm »
I also had weird errors cause by Bison in a dozen files, because it made files which then g++ complained about "error: invalid conversion from ‘const char*’ to ‘char*’ " and "ISO C++ forbids converting a string constant to ‘char*’ ".

This is one of the twelve lines in the Makefiles that exposes this issues in the generated "axm.tab.c" file
Code: [Select]
axm.tab.c: Parser/axm.y
        bison -v --name-prefix=axm -d Parser/axm.y

I used /usr/bin/sed to manually change "const char" into "char" before Makefiles invokes C++.

Code: [Select]
          $(CXX) $(CXX_FLAGS) -c axm.tab.c -o axm-parser.o

Ugly, but at least it compiles and seems working (edit: it has just passed all the tests) :D

I think this project needs a serious rewrite. There are too many parts with ugly things. Unfortunately I am not skilled with C++ and Bison (never used it), so I can't do any definite fix.

I am trying to contact the authors. Hope they will fix stuff once for all.
« Last Edit: December 27, 2020, 10:52:35 pm by DiTBho »
The opposite of courage is not cowardice, it is conformity. Even a dead fish can go with the flow
 

Offline janoc

  • Super Contributor
  • ***
  • Posts: 3851
  • Country: de
Re: [solved] C++ no match for call to hasher ???
« Reply #12 on: December 27, 2020, 11:12:47 pm »
[..] you have a strange idea about what consists a large C++ project.

The above posted code got found Googling, and comes from StackOverflow, but it's confused and doesn't solve anything. I found it Googling about the strange error I got compiling a project of 2.000 C++ files.

Aren't 2.000 files "enough" for you to define it as "large C++ project" ?  :D

Depends. 2000 small files is not much. I am used to codebases like the Unreal Engine which is over 2 millions of lines of C++ code. Or Zephyr, which has more than 22000 source files ...

Quote
I am trying to contact the authors. Hope they will fix stuff once for all.

I wouldn't have high hopes - given that that code was designed for an ancient version GCC, it is most likely unmaintained. The Bison errors you have are sorta normal. Bison generates a C file and the code compiles it as C++ for whatever reason, which is much more restrictive when pointer types are concerned. That's a poor design which isn't OK in modern C++.

« Last Edit: December 27, 2020, 11:17:17 pm by janoc »
 
The following users thanked this post: DiTBho


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf