错误:"哈希"不是类模板
error: 'hash' is not a class template
#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>
时,我收到了相同的错误消息。
您专门研究全局命名空间std::hash<>
,这是格式不正确的。
专用化必须在同一命名空间中声明,std
.请参阅std::hash
的示例:
// custom specialization of std::hash can be injected in namespace std
namespace std
{
template<> struct hash<S>
{
typedef S argument_type;
typedef std::size_t result_type;
result_type operator()(argument_type const& s) const
...
相关文章:
- C++哈希表中,两个相同的实现,但一个给出错误
- 自定义哈希表实现-将字符串映射到整数时出现内存错误
- 错误:哈希函数必须可使用键类型的参数进行调用
- 代码块中的哈希库++库"No such file or directory"错误
- 错误:"哈希"不是类模板
- 使用对数据类型的向量的哈希表中的分段错误错误
- 测试完美哈希函数时超出范围错误
- 在哈希表复制构造函数中找不到错误
- 编译哈希算法时出现内存访问冲突错误
- 错误 c2338 C++ 标准不提供此类型的哈希
- 哈希映射错误:与调用 '(const __gnu_cxx::.
- 哈希函数错误,c++
- 将链接哈希表初始化为 NULL。获取"lvalue required as left operand of assignment"错误。为什么?这是我的代码:
- 哈希表中存在分段错误
- 当用户自定义哈希函数在 unordered_map 中时,无法解码 g++ 中模糊的编译器错误
- 逐行散列文件时错误的 md5 哈希值
- 返回错误值的双哈希函数
- 为什么我在为矢量实现这个简单的哈希时出现错误<int>?
- 实现哈希表(rehash范围错误)
- 使用Crypto++进行MD4哈希会导致错误的哈希