我使用ADS 1.2编译器移植使用cpp编写的代码来支持ARM9,但在移植下面的代码后,使用RVCT2.2编译器编译ARM11时出错,这是示例代码
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();
答案 0 :(得分:0)
您遇到的问题是std::map
的分配器需要成对
std::pair<const Key, T>
对不对,
pair<int*,list<int,allocator<int> > >
与您没有Key
const限定的情况不同。它应该是
pair<int* const,list<int,allocator<int> > >
由于您使用的是标准分配器,因此没有理由指定分配器。你可以使用
list<int> mystack;
map<int*,list<int>> mymap;
mymap[addr] = mystack;
该列表默认使用std::allocator<int>
,地图默认使用std::less<int*>
和std::allocator<int * const, std::list<int>>
同样不是std::less<int*>
不会比较int*
指向的值,而是比较地址。如果你需要前者,你需要编写自己的比较对象来做到这一点。