gpt4 book ai didi

c++ - std::list.erase(itor) 在 Android 和 Win32 之间有区别

转载 作者:行者123 更新时间:2023-11-30 01:43:04 25 4
gpt4 key购买 nike

如果我在 for 循环中使用 iterator 并且在迭代器的当前迭代中使用 erase,我发现 AndroidWIN32

std::list<StackData*>::iterator itor;
std::list<StackData*>::iterator firstDelItor = __mStack.begin();
for(itor = __mStack.begin(); itor != __mStack.end();)
{
firstDelItor = itor;
PRINT_LOG(LOG_TAG, "A itor[%p] firstDelItor[%p]", *itor, *firstDelItor);
itor = __mStack.erase(itor);
PRINT_LOG(LOG_TAG, "B itor[%p] firstDelItor[%p]", *itor, *firstDelItor);
...
}

Android : erase(itor)后,firstDelItor的值不变。

23766-23766 D/TAG: A itor[0x9b979fe0] firstDelItor[0x9b979fe0]
23766-23766 D/TAG: B itor[0x9b8e9dbc] firstDelItor[0x9b979fe0]

在 WIN32 上:firstDelItor 的值更改为 0xdddddddd

TAG : A itor[0C6172D8] firstDelItor[0C6172D8]
Fatal at PRINT_LOG(LOG_TAG, "B itor[%p] firstDelItor[%p]", *itor, *firstDelItor); (itor = 0xcdcdcdcd, firstDelItor = 0xdddddddd)

所以,请解释一下AndroidWIN32在这种情况下的区别。

最佳答案

“对已删除元素的引用和迭代器已失效。” http://en.cppreference.com/w/cpp/container/list/erase

关于c++ - std::list.erase(itor) 在 Android 和 Win32 之间有区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38430347/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com