-
-
Notifications
You must be signed in to change notification settings - Fork 7.7k
Closed
Labels
Description
Description
Non compiling code - tried on Windows and GitPod.
gitpod /workspace/C-Plus-Plus $ g++ hashing/chaining.cpp -Wall -o test
hashing/chaining.cpp: In function ‘int main()’:
hashing/chaining.cpp:85:17: error: reference to ‘hash’ is ambiguous
85 | h = hash(x, mod);
| ^~~~
In file included from /usr/include/c++/9/bits/basic_string.h:6719,
from /usr/include/c++/9/string:55,
from /usr/include/c++/9/bits/locale_classes.h:40,
from /usr/include/c++/9/bits/ios_base.h:41,
from /usr/include/c++/9/ios:42,
from /usr/include/c++/9/ostream:38,
from /usr/include/c++/9/iostream:39,
from hashing/chaining.cpp:2:
/usr/include/c++/9/bits/functional_hash.h:58:12: note: candidates are: ‘template<class _Tp> struct std::hash’
58 | struct hash;
| ^~~~
hashing/chaining.cpp:47:5: note: ‘int hash(int, int)’
47 | int hash(int x, int mod) { return x % mod; }
| ^~~~
hashing/chaining.cpp:92:17: error: reference to ‘hash’ is ambiguous
92 | h = hash(x, mod);
| ^~~~
In file included from /usr/include/c++/9/bits/basic_string.h:6719,
from /usr/include/c++/9/string:55,
from /usr/include/c++/9/bits/locale_classes.h:40,
from /usr/include/c++/9/bits/ios_base.h:41,
from /usr/include/c++/9/ios:42,
from /usr/include/c++/9/ostream:38,
from /usr/include/c++/9/iostream:39,
from hashing/chaining.cpp:2:
/usr/include/c++/9/bits/functional_hash.h:58:12: note: candidates are: ‘template<class _Tp> struct std::hash’
58 | struct hash;
| ^~~~
hashing/chaining.cpp:47:5: note: ‘int hash(int, int)’
47 | int hash(int x, int mod) { return x % mod; }
| ^~~~
hashing/chaining.cpp:98:52: error: reference to ‘hash’ is ambiguous
98 | cout << "Hash of " << x << " is = " << hash(x, mod);
| ^~~~
In file included from /usr/include/c++/9/bits/basic_string.h:6719,
from /usr/include/c++/9/string:55,
from /usr/include/c++/9/bits/locale_classes.h:40,
from /usr/include/c++/9/bits/ios_base.h:41,
from /usr/include/c++/9/ios:42,
from /usr/include/c++/9/ostream:38,
from /usr/include/c++/9/iostream:39,
from hashing/chaining.cpp:2:
/usr/include/c++/9/bits/functional_hash.h:58:12: note: candidates are: ‘template<class _Tp> struct std::hash’
58 | struct hash;
| ^~~~
hashing/chaining.cpp:47:5: note: ‘int hash(int, int)’
47 | int hash(int x, int mod) { return x % mod; }
| ^~~~
gitpod /workspace/C-Plus-Plus $ Original author: @vasutomar
Expected Behavior
Unknown.. no explanation provided anywhere. Should compile at least.
Actual Behavior
Possible Fix
See attached possible fix. But the code does not seem to give expected results.
Steps to Reproduce
- Open the repo in GitPod using the link provided in the Readme file.
- From the terminal, issue compilation command as shown in the description above.
Context
Trying to enable CMake auto-configure and compile for files in the folder.