2013-07-09 19 views
0

代碼,我有以下代碼:面臨的一個問題,而編譯使用C++地圖

D:/Y24\usr\include/xmemory", line 144: error(483): function 
      "std::allocator<_Ty>::address(std::_Allocator_base<_Ty>::value_type 
      &) const [with _Ty=const CosTransactions::otid_t]" has already been 
      declared 
      detected during: 
      instantiation of class 

我使用HP:

std::map< 
    const CosTransactions::otid_t, 
    std::pair< 
     CosTransactions::otid_t, 
     CosTransactions::Coordinator_ptr>, 
    otid_t_less> XID_Broker_impl::cache; 
編譯我如下得到一個錯誤上面的代碼時

-Nonstop C++編譯器?當我刪除地圖中的鍵「const」時,錯誤消失。這是否意味着我不能在地圖中使用「const key」? 請幫我在這個問題上

回答

1

從C++ 11§23.3.1類模板地圖

For a map<Key,T> the key_type is Key and the value_type is pair <const Key,T> 

注意這裏關鍵的類型是const根據定義,這意味着你不應該申報鍵類型爲const