我正在移植用cpp编写的代码,以使用ADS 1.2编译器支持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();
最佳答案
您遇到的问题是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>
, map 将默认使用std::less<int*>
和std::allocator<int * const, std::list<int>>
同样不是
std::less<int*>
不比较int*
指向的值,而是比较地址。如果需要前者,则需要编写自己的比较对象。
关于c++ - 使用ADS 1.2编译器和ARM11 RVCT2.2为ARM9编码时映射错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38395951/