2013-01-09 65 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

相關問題