[solved] C++ no match for call to hasher ??? - Page 1
Forum section: electronics / general

author: DiTBho
author_rank: Super Contributor
timestamp: December 27, 2020, 11:40:17 am
content: 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.cppCode:/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:#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 variablereadFile >> tempRead;for (int i =0; i<400; i++){//create new object each timeMap2 *mapNode = new Map2(tempPop,tempID,tempKey,tempUser,tempDesc);//insert each time new object is mademap1.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 valuepair<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);}elsereturn 0;}map.hCode:#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();}#endifAnyone has an idea? Workaround? or any doc-suggestion to look at?

author: DiTBho
author_rank: Super Contributor
timestamp: December 27, 2020, 11:56:56 am
content: Code:CXXFLAGS=-g -std=c++11I have this in the Makefile.

author: DiTBho
author_rank: Super Contributor
timestamp: December 27, 2020, 11:59:29 am
content: This is the line where g++ traps error/usr/lib/gcc-v10.2.0/include/g++-v10/backward/hashtable.h:604:23:Code:size_type_M_bkt_num_key(const key_type& __key, std::size_t __n) const{ return _M_hash(__key) % __n; }

author: janoc
author_rank: Super Contributor
timestamp: December 27, 2020, 01:22:27 pm
content: When asking stuff like thisalwayspost 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: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.

author: DiTBho
author_rank: Super Contributor
timestamp: December 27, 2020, 01:45:08 pm
content: Quote from: janoc on December 27, 2020, 01:22:27 pmI 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.

author: magic
author_rank: Super Contributor
timestamp: December 27, 2020, 01:48:57 pm
content: I would go as far as suggesting the contrary: only post the first error messageG++ 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.

author: DiTBho
author_rank: Super Contributor
timestamp: December 27, 2020, 01:52:56 pm
content: Quote from: janoc on December 27, 2020, 01:22:27 pmOk, so forget the posted code above; when I try to compile the big project, the first error I encounter is:Code:/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:609Code:607: size_type608: _M_bkt_num_key(const key_type& __key, size_t __n) const609: { return _M_hash(__key) % __n; }Note I am using g++ v9.3.0 now.The same happens with g++ v4.7

author: magic
author_rank: Super Contributor
timestamp: December 27, 2020, 02:08:57 pm
content: 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::blahablareplace all occurences of hash_(multi)map with unordered_(multi)mapAs 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.

author: DiTBho
author_rank: Super Contributor
timestamp: December 27, 2020, 03:36:40 pm
content: 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 workThank you! You saved my day

author: janoc
author_rank: Super Contributor
timestamp: December 27, 2020, 07:29:31 pm
content: Quote from: DiTBho on December 27, 2020, 01:45:08 pmWell, 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.Quote from: DiTBho on December 27, 2020, 03:36:40 pmGood, glad to see you have managed to fix that.

author: DiTBho
author_rank: Super Contributor
timestamp: December 27, 2020, 09:48:35 pm
content: Quote from: janoc on December 27, 2020, 07:29:31 pmThe 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" ?

author: DiTBho
author_rank: Super Contributor
timestamp: December 27, 2020, 10:06:08 pm
content: 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" fileCode:axm.tab.c: Parser/axm.ybison -v --name-prefix=axm -d Parser/axm.yI used /usr/bin/sed to manually change "const char" into "char" before Makefiles invokes C++.Code:$(CXX) $(CXX_FLAGS) -c axm.tab.c -o axm-parser.oUgly, but at least it compiles and seems working (edit: it has just passed all the tests)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.

author: janoc
author_rank: Super Contributor
timestamp: December 27, 2020, 11:12:47 pm
content: Quote from: DiTBho on December 27, 2020, 09:48:35 pmDepends. 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 ...QuoteI 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++.