c++ - 错误 : 'hash' is not a class template

标签 c++ c++11 hash

#include <unordered_map>
#include <memory>
#include <vector>

template<> // Voxel has voxel.position which is a IVec2 containing 2 values, it also has a bool value
struct hash<Voxel> {  
size_t operator()(const Voxel & k) const  
    {  
        return Math::hashFunc(k.position);  
    }  
};  

template<typename T> // This was already given
inline size_t hashFunc(const Vector<T, 2>& _key)
{
    std::hash<T> hashfunc;
    size_t h = 0xbd73a0fb;
    h += hashfunc(_key[0]) * 0xf445f0a9;
    h += hashfunc(_key[1]) * 0x5c23b2e1;
    return h;
}

我的主要

int main()
{
    Voxel t{ 16,0,true };
    std::hash(t);
}

现在我正在写 std::hash 的特化。现在在线提交页面总是为我的代码返回以下错误。我不知道为什么以及我做错了什么。

error: 'hash' is not a class template struct hash<>

error: no match for call to '(const std::hash<Math::Vector<int, 2ul> >)   (const Math::Vector<int, 2ul>&)' noexcept(declval<const_Hash((declval<const_Key&>()))>.

我自己的编译器只抛出

error: The argument list for "class template" std :: hash "" is missing.

最佳答案

为了后代,当我忘记 #include <functional> 时,我得到了同样的错误信息。 .

关于c++ - 错误 : 'hash' is not a class template,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44496509/

相关文章:

c++ - 类似iOS UIKit Dynamics的Qt/C++物理引擎

C++ 模块化框架(如 OSGi)?

c++ - 将 vector<Foo> 转换为 vector<double> 并找到最小值

ruby-on-rails - 我如何在拒绝中的嵌套哈希上使用 except

arrays - 如何循环遍历 Perl 哈希数组数组?

c++ - 在 C++ 中定义类指针

c++ - 获取二叉搜索树中的节点数

java - 为什么我的自定义封闭哈希集中会发生如此多的冲突?

c++ - 为什么 std::array 临时 constexpr 的 operator[] 不是?

c++ - 数组成员的初始化程序无效