2014-04-06 137 views
0

2問題:
1.我真的需要通過成員傳遞參數來修改/ modify_key嗎?
2.爲什麼我有這樣的編譯錯誤
multi_index模板編譯錯誤

要查看與錯誤的整個代碼,你可以看看http://coliru.stacked-crooked.com/a/d6241361318e1925

誤差

MultiIndex4.h: In member function 'uint32_t CrMultiParameterMultiIndex::ModifyKeyBy(SearchingKey&, ModifyKeyType&) [with SearchingTagType = IMEI_tag, ModifyingTagType = IMEI_tag, SearchingKey = uint32_t, ModifyKeyType = uint32_t]': 
MultiIndex4.h:183: instantiated from here 
MultiIndex4.h:119: error: no matching function for call to 'boost::multi_index::multi_index_container<UsersKey, UsersKey_indices, std::allocator<UsersKey> >::modify_key(boost::multi_index::detail::bidir_node_iterator<boost::multi_index::detail::ordered_index_node<boost::multi_index::detail::index_node_base<UsersKey, std::allocator<UsersKey> > > >&, boost::function<void()(uint32_t&)>&)' 
*** Errors occurred during this build *** 

我有一個類CrMultiParameterMultiIndex那擁有2個索引的多索引。

我試着創建一個模板函數,它只能根據關鍵字的一部分進行搜索並只修改關鍵字的一部分。

這個類有一個輔助函數,使用它

template <typename TagType,typename SearchingKey> 
typename GlobalHash::index<TagType>::type::iterator GetIteratorBy(SearchingKey & key){ 
    return m_pGlobalHash->get<TagType>().find(key) ; 
} 

,修改功能

template <typename SearchingTagType,typename ModifyingTagType,typename SearchingKey,typename ModifyKeyType> uint32_t ModifyKeyBy(SearchingKey & key,ModifyKeyType & pi_Modifykey) 
    { 
    uint32_t hRes = 1; 

    //search for entry by TagType 
    typedef typename GlobalHash::index<SearchingTagType>::type  IndexType; 
    typename IndexType::iterator it = GetIteratorBy<SearchingTagType>(key); 

    //entry found 
    if(it != m_pGlobalHash->get<SearchingTagType>().end()) 
    { 
     //Set parameter to modify 
     hRes = SetParameterKeys<ModifyingTagType>(pi_Modifykey); 

     if(hRes == 1) 
     { 
      //get iteraror to modify 
      typedef typename GlobalHash::index<ModifyingTagType>::type  ModifyIndexType; 
      typename ModifyIndexType::iterator itToModify = m_pGlobalHash->get<ModifyingTagType>().iterator_to(*it); 

      boost::function<void(ModifyKeyType &)> f = boost::bind(&CrMultiParameterMultiIndex::ModifyKey<ModifyingTagType, ModifyKeyType >, this, _1); 

      //modify key failed 
      if(m_pGlobalHash->modify_key(itToModify , f)==false) 
       hRes = 0; 
     } 
    } 
    //entry not found 
    else 
     hRes = 0; 
    return hRes; 
} 

這個編譯

uint64_t nFromImsi = 1; 
uint64_t nToImsi = 1; 
m_multiParam.ModifyKeyBy<IMSI_tag,IMSI_tag>(nFromImsi,nToImsi) 

但不是這個

uint32_t nFromImsi = 1; 
uint32_t nToImsi = 1; 
m_multiParam.ModifyKeyBy<IMEI_tag,IMEI_tag>(nFromImsi,nToImsi) 

爲什麼?以及它如何可以編譯

,這裏是修飾語

template <> inline void CrMultiParameterMultiIndex::ModifyKey<IMEI_tag>(uint32_t & po_Key){po_Key = m_ParameterKeys.IMEI;} 
template <> inline void CrMultiParameterMultiIndex::ModifyKey<IMSI_tag>(uint64_t & po_Key){po_Key = m_ParameterKeys.IMSI;} 

回答

2

大衛,

if(m_pGlobalHash->modify_key(itToModify , f)==false) 

謊言在事實的問題m_pGlobalHash是索引#0視圖(order_by_IMSI)並且不接受迭代器來查看#1(order_by_IMEI)。您可以選擇project iterators或選擇適當的索引:

if(m_pGlobalHash->get<ModifyingTagType>().modify_key(itToModify , f)==false) 
+0

感謝您的回答。我真的需要通過成員傳遞參數來修改/ modify_key嗎? – davidbobo

+0

[coliru](http://coliru.stacked-crooked.com/a/4586d3c48d1b4a55) –

+0

對不起,我不理解你關於傳遞參數「通過成員」的問題,謹慎詳細說明? –