c++ - 使用ADS 1.2编译器和ARM11 RVCT2.2为ARM9编码时映射错误

标签 c++ stl compiler-errors ads arm9

我正在移植用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/

相关文章:

c# - 为什么循环不起作用?为什么在局部变量 "y"总是 int 而 s counter = 1 = int

c++ - 调用 qExec "no known conversion for argument 1 to QObject"时出错

c++ - 生成变量的名称

C++:opencv 上的 libpng 冲突

c++ - 如何 LRU 缓存大量由 C++ STL 重型结构构成的对象?

C++:具有 STL 类型和自定义类型的优雅 "polymorphism"?

c++ - 从输入操作前缀表达式

c++ - 转换 std::basic_string<wchar_t> 和 std::basic_string<uint16_t>

c# - 并非所有代码路径都返回值: Unity

c++ - 返回类型不完整的调用方法和我无法解释的模板解决方法