0

I'm porting my code which written in cpp to support ARM9 using ADS 1.2 compiler,but after porting the below code gives error while compiling for ARM11 using RVCT2.2 compiler, this is the sample code

list<int,allocator<int> > mystack;
map<int*,list<int,allocator<int> >,less<int*>,allocator<pair<int*,list<int,allocator<int> > > > > mymap;
mymap[addr] = mystack;
Error 1:Error:  #167:argument of type "std::allocator<std::pair<int *,
std::list<int, std::allocator<int>>>>::const_pointer" is incompatible with
parameter of type "std::allocator<std::pair<int *, std::list<int, 
std::allocator<int>>>>::pointer"

Error 2:Error:  #434: a reference of type 
"__rw::__rw_tree_iter<__rw::__rb_tree<std::map<int *, std::list<int, 
std::allocator<int>>, std::less<int *>, std::allocator<std::pair<int *, 
std::list<int, std::allocator<int>>>>>::key_type, std::map<int *, 
std::list<int, std::allocator<int>>, std::less<int *>, 
std::allocator<std::pair<int *, std::list<int, 
std::allocator<int>>>>>::value_type,  (not const-qualified) cannot be 
initialized with a value of type "std::map<int *, std::list<int, 
std::allocator<int>>, std::less<int *>, std::allocator<std::pair<int *, 
std::list<int, std::allocator<int>>>>>::value_type"
          return _C_node->_C_value();
4

1 回答 1

0

The problem you have is the allocator for std::map needs to be pair of

std::pair<const Key, T>

Right not you have

pair<int*,list<int,allocator<int> > >

Which is not the same as you do not have the Key const qualified. It should be

pair<int* const,list<int,allocator<int> > >

Since you are using the standard allocator there is no reason to specify the allocator. You can just use

list<int> mystack;
map<int*,list<int>> mymap;
mymap[addr] = mystack;

And the list will default to using a std::allocator<int> and the map will default to using std::less<int*> and std::allocator<int * const, std::list<int>>

Also not that std::less<int*> do not compare the values the int* points to but instead it compares the address. If you need the former you need to write your own comparison object to do that.

于 2016-07-15T12:27:13.953 回答