【问题标题】:android ndk crash when using stl map 's operator []使用 stl map 的操作符 [] 时 android ndk 崩溃
【发布时间】:2013-03-18 07:01:50
【问题描述】:

我有一张地图: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));

这是为什么?

【问题讨论】:

  • 这似乎不是 Android 特有的问题。

标签: android c++ map stl android-ndk


【解决方案1】:

你知道你使用的是什么版本的 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/

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多