Jump to content
  • Advertisement
Sign in to follow this  
RegularKid

STL hash_map errors...

This topic is 3620 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I'm trying to use an STL hash_map in my project ( on a Mac using XCode ) and I'm getting some compiler errors when attempting to use the hash_map function "find". Here is how I'm declaring my hash_map:
hash_map<double, MyClass*> myHash;

I can then add elements into the hash like so without any problems:
myHash[ 0 ] = new MyClass();
myHash[ 5 ] = new MyClass();

This all works fine, but when I try to use the find() function like this:
if( myHash.find( 3 ) == myHash.end() )
{
    printf( "Couldn't find hash entry!\n");
}

Then I get the following errors when I compile: "error: no match for call to '(const __gnu_cxx::hash<double>)(const double&)'" I'm not sure what's going on. I tried even adding my own hash function for it like this:
struct eqdouble
{
    bool operator()(double s1, double s2) const
    {
        return s1 == s2;
    }
};
hash_map<double, MyClass*, hash<double>, eqdouble> myHash;

However, that didn't seem to do anything different ( I'm assuming there is already a built in hash function for a double ). Any help would be great! Thanks!

Share this post


Link to post
Share on other sites
Advertisement
Hey,

Sorry, I should have been more clear in my original thread. I'm using a double variable to pass into find() ( i'm just using the 3 constant as an example ).

Share this post


Link to post
Share on other sites
Just to chime in on C++ and floats/doubles, if you end up doing any math on them they are not gonna give you exact results which may make it difficult to accurately get the same value over and over for retrieval. Unless you really need it I would use an int as your key value.

Honestly unless the speed is a huge issue I would just use std::map.
BTW hash_map is no longer part of the STL I think its part of stdext or something similar.

I know neither of those comments cleared up your compiler error. To me it looks like there is no hashing function for double that the compiler can find, again I recommend trying int.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!