1

I am using a user defined class as keys in a std::hash_map. I have implemented my custom hash function/structure but its giving me compiler errors. I dont understand what the issue is?

Compiler Error:

Error 2 error C2065: 'bucket_size' : undeclared identifier
Error 1 error C2039: 'bucket_size' : is not a member of 'HashComponent'

class Component
{
public:
    const int id;

    Component(const int& id) : id(id) { }

    bool operator== (const Component& other) const
    {
        return id == other.id;
    }
};

struct HashComponent
{
    std::size_t operator()(const Component& cmp) const
    {
        using std::size_t;
        using std::hash;

        return hash<int>()(cmp.id) ^ 32;
    }
};

std::hash_map<Component, int, HashComponent> cMap; // causes compiler error
sazr
  • 24,984
  • 66
  • 194
  • 362
  • 2
    `hash_map` is not in the C++ Standard Library. Use `std::unordered_map` if you have the choice. – R Sahu Dec 27 '15 at 05:09
  • @RSahu it isn't? I thought it was part of C++ stl < 98? And unordered_map is the newer (introduced in C++98?)? – sazr Dec 27 '15 at 05:16
  • 2
    You might want to [read this](http://stackoverflow.com/questions/5205491/whats-this-stl-vs-c-standard-library-fight-all-about), and learn the difference between the STL and the standard library. – Some programmer dude Dec 27 '15 at 05:17
  • @JakeM, The STL has/had `hash_map` but the C++ Standard Library does not. See http://stackoverflow.com/questions/5908581/is-hash-map-part-of-the-stl. – R Sahu Dec 27 '15 at 05:23

0 Answers0