HashMap自定义哈希不会编译

时间:2015-12-27 05:00:48

标签: c++ stl

我使用用户定义的类作为std::hash_map中的键。我已经实现了我的自定义哈希函数/结构,但它给了我编译器错误。我不明白这个问题是什么?

编译器错误:

  

错误2错误C2065:' bucket_size' :未声明的标识符
  错误1错误C2039:' bucket_size' :不是' 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

0 个答案:

没有答案