2013-01-09 61 views
4

没有匹配的功能,当我声明一个unordered_map如下:插入unordered_map

boost::unordered_map<std::array<char, 20>, t_torrent> torrent_ins; 

,然后插入一个元素到它(在壳体中的键已经不存在,此映射将返回的一个参考新元素)

t_torrent& torrent_in = torrent_ins[to_array<char,20>(in)]; 

但我得到一个错误信息:

../src/Tracker/torrent_serialization.cpp:30: instantiated from here/usr/local/include/boost/functional/hash/extensions.hpp:176: error: no matching function for call to ‘hash_value(const std::array<char, 20ul>&)’ 

有限公司你们帮我解释这个错误吗?非常感谢!

回答

8

这是因为std::array<char, 20>没有“默认”哈希函数,至少没有实现提供。您必须提供std::array<char, 20>的散列函数,然后才能使您的代码正常工作。

正如你可以看到std::unordered_map,:

template< 
    class Key, 
    class T, 
    class Hash = std::hash<Key>, 
    class KeyEqual = std::equal_to<Key>, 
    class Allocator = std::allocator< std::pair<const Key, T> > 
> class unordered_map; 

您必须Key类型提供定制的散列函数提供Hash

相关问题