我尝试如下初始化unordered_map:
unordered_multimap<struct index,int>index_hash;
,结构定义为:
struct index
{
int i;
int j;
int k;
index(int a, int b, int c)
{
i = a;
j = b;
k = c;
}
};
当我在Visual Studio上编码时,根本没有语法错误,并且在编译后发生了错误:
error: no match for call to ‘(const std::hash<index>) (const index&)’ noexcept(declval<const _Hash&>()(declval<const _Key&>()))>
^ In file included from /usr/include/c++/5/bits/move.h:57:0,
from /usr/include/c++/5/bits/stl_pair.h:59,
from /usr/include/c++/5/bits/stl_algobase.h:64,
from /usr/include/c++/5/vector:60,
from neighbors/../../cpp_utils/cloud/cloud.h:22,
from neighbors/neighbors.h:3,
from neighbors/neighbors.cpp:2: /usr/include/c++/5/type_traits: In instantiation of ‘struct
std::__not_<std::__and_<std::__is_fast_hash<std::hash<index> >,
std::__detail::__is_noexcept_hash<index, std::hash<index> > > >’:
/usr/include/c++/5/bits/unordered_map.h:853:67: required from ‘class
std::unordered_multimap<index, int>’ neighbors/neighbors.cpp:686:38:
required from here