gpt4 book ai didi

c++ - 我如何编写一个 for 循环来遍历 CAtlMap 有选择地删除元素?

转载 作者:行者123 更新时间:2023-11-28 04:01:29 33 4
gpt4 key购买 nike

我正在尝试在没有太多特殊情况代码的情况下执行以下操作来处理无效的 POSITION 等:

填空的最佳方法是什么?

void DeleteUnreferencedRecords(CAtlMap<Record>& records)
{
for(____;____;____)
{
if( NotReferencedElsewhere(record) )
{
// Delete record
_______;
}
}
}

最佳答案

据此:

http://msdn.microsoft.com/en-us/library/0h4c3zkw(VS.80).aspx

RemoveAtPos 具有这些语义

Removes the key/value pair stored at the specified position. The memory used to store the element is freed. The POSITION referenced by pos becomes invalid, and while the POSITION of any other elements in the map remains valid, they do not necessarily retain the same order.

问题是顺序可以改变——这意味着 GetNext() 不会真正继续迭代。看起来您需要一次收集要删除的 POSITION 并在下一次删除它们。删除 POSITION 不会使其他 POSITION 对象无效

关于c++ - 我如何编写一个 for 循环来遍历 CAtlMap 有选择地删除元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/197121/

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