The following example will not compile for me:
#include <iostream>
#include <functional>
#include <string>
int main()
{
std::string str = "Meet the new boss...";
std::hash<std::string> hash_fn;
size_t str_hash = hash_fn(str);
std::cout << str_hash << '\n';
}
I get the following output from g++
> g++ -o test test.cpp
test.cpp: In function ‘int main()’:
test.cpp:8: error: ‘hash’ is not a member of ‘std’
test.cpp:8: error: expected primary-expression before ‘>’ token
test.cpp:8: error: ‘hash_fn’ was not declared in this scope
Am I missing a compile flag or something?
Related info:
> g++ -v
Using built-in specs.
Target: i686-apple-darwin10
Configured with: /var/tmp/gcc/gcc-5666.3~6/src/configure --disable-checking --enable-werror --prefix=/usr --mandir=/share/man --enable-languages=c,objc,c++,obj-c++ --program-transform-name=/^[cg][^.-]*$/s/$/-4.2/ --with-slibdir=/usr/lib --build=i686-apple-darwin10 --program-prefix=i686-apple-darwin10- --host=x86_64-apple-darwin10 --target=i686-apple-darwin10 --with-gxx-include-dir=/include/c++/4.2.1
Thread model: posix
gcc version 4.2.1 (Apple Inc. build 5666) (dot 3)
> uname -a
Darwin ############# 10.8.0 Darwin Kernel Version 10.8.0: Tue Jun 7 16:33:36 PDT 2011; ro
found the answer here
this code compiles:
#include <iostream>
#include <tr1/functional>
#include <string>
int main()
{
double d = 3;
std::tr1::hash<double> hash_fn;
size_t str_hash = hash_fn(d);
std::cout << str_hash << '\n';
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With