0

I have the following code :

std::map<
    const CosTransactions::otid_t,
     std::pair<
        CosTransactions::otid_t,
        CosTransactions::Coordinator_ptr>,
    otid_t_less> XID_Broker_impl::cache;

when compiling the above code I am getting an error as follows:

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

I am using HP-Nonstop C++ compiler? when I remove the "const" of key in map , the error goes away. Does this means that I cannot use "const key" in map? Please help me on this question

fatihk
  • 7,789
  • 1
  • 26
  • 48
whitetiger
  • 412
  • 1
  • 4
  • 13

1 Answers1

1

From C++11 ยง23.3.1 Class template map

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

Note here key type is const by definition, which implies that you shouldn't declare the key type as const again.

Yu Hao
  • 119,891
  • 44
  • 235
  • 294