#include <iostream>
using namespace std;
 
int main(int argc, char * argv[])
{
        hash<const char*> H;
        cout << "foo() ->" << H("foo()") << endl;
}

compilation error after
g++ -c -g main.cc
is :

main.cc: In function `int main(int, char**)':
main.cc:8: error: `hash' undeclared (first use this function)
main.cc:8: error: (Each undeclared identifier is reported only once for each 
   function it appears in.)
main.cc:8: error: syntax error before `char'
main.cc:9: error: `H' undeclared (first use this function)

why?
thanx

Recommended Answers

All 6 Replies

>>why?
where did you declare hash ? I think it is probably declared in one of the boost libraries.

what do u mean by boost library?

Member Avatar for iamthwee

As in there is no standard hash library in c++ duh?

>why?
It depends. Where in the world do you think the hash<> template is coming from?

#include <functional> and use gcc 4.3 with the switch -std=c++0x

#include <iostream>
#include <functional>
using namespace std;
 
int main(int argc, char * argv[])
{
        hash<const char*> H;
        cout << "foo() ->" << H("foo()") << endl;
}
// g++43 -std=c++0x -Wall -c -g main.cc
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.