使用STL map的运算符[]时android ndk崩溃

标签 android c++ dictionary stl android-ndk

我有一张 map :map < int64_t, Item* > m_items ;

当使用m_items[one_id]时,我的应用程序崩溃了。 但如果我使用 map<int64_t, Item*>::iterator iter = m_items.find(one_id) ,没关系。

如果我需要添加一个项目,我必须使用:m_items.insert(make_pair(one_id, one_item));

这是为什么?

最佳答案

您知道您使用的 gcc 版本是什么吗? 如果是 gcc 4.5 或更早版本,gcc 中的此错误会导致 Boost 的无序映射的 [] 运算符无法正常运行:http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40145 也许您正在看到类似的东西。

如果是gcc 4.6我不确定,但是C++11 at()方法将可供你使用,它有点慢,但它比find更快。 http://www.cplusplus.com/reference/map/map/at/

关于使用STL map的运算符[]时android ndk崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15471303/

相关文章:

python - 使用嵌套字典替换 pandas 数据框中的值

python-3.x - 无法将网络抓取输出作为字典返回

Android Studio,如何通过http发送数据?

c++ - 删除除某些位置以外的特定位置的元素

android - setOnItemClickListener() 不适用于自定义 ListView @ Android

c++ - 使用代码将字符集设置为多字节

c++ - 有人能解释一下这段代码是如何执行的吗?

c# - 发送一个 JSON 数组以作为 Dictionary<string,string> 接收

java - 改造预计为 BEGIN_ARRAY,但实际为 BEGIN_OBJECT

android - Firebase 身份验证 : Verify email before sign up