我有以下的無序多重映射:遍歷equal_range結果集
std::tr1::unordered_multimap<unsigned int, unsigned int > duplicates;
我嘗試使用
std::pair<std::tr1::unordered_multimap<unsigned int, unsigned int>,std::tr1::unordered_multimap<unsigned int, unsigned int> > range = duplicates.equal_range(id);
獲得關鍵的值,然後使用for循環,以獲得多結果:
for (std::tr1::unordered_multimap<unsigned int, unsigned int>::iterator it=range.first; it!=range.second; ++it)
,但我得到了以下錯誤:
ref_impl/core.cpp:306:84: error: conversion from 'std::tr1::unordered_multimap<unsigned int, unsigned int>' to non-scalar type 'std::tr1::_Hashtable<unsigned int, std::pair<const unsigned int, unsigned int>, std::allocator<std::pair<const unsigned int, unsigned int> >, std::_Select1st<std::pair<const unsigned int, unsigned int> >, std::equal_to<unsigned int>, std::tr1::hash<unsigned int>, std::tr1::__detail::_Mod_range_hashing, std::tr1::__detail::_Default_ranged_hash, std::tr1::__detail::_Prime_rehash_policy, false, false, false>::iterator {aka std::tr1::__detail::_Hashtable_iterator<std::pair<const unsigned int, unsigned int>, false, false>}' requested
ref_impl/core.cpp:306:101: error: no match for 'operator!=' in 'it != range.std::pair<std::tr1::unordered_multimap<unsigned int, unsigned int>, std::tr1::unordered_multimap<unsigned int, unsigned int> >::second'
有什麼建議嗎?
我在使用auto時得到以下內容:warning:'auto'在C++ 11中更改含義;請刪除它[-WC++ 0x-compat] – glarkou 2013-03-16 02:20:32
@salamis:你在使用什麼編譯器?嘗試在編譯時向命令行添加「-std = C++ 11」或「-std = C++ 0x」。 – 2013-03-16 02:21:51
我在Mac OS上使用4.7.2 – glarkou 2013-03-16 02:23:43