为什么具有 list<struct type>::itrator 的 struct 不能通过 clear() 删除?
Why struct which have list<struct type>::iterator can't delete by clear()?
我是iOS开发人员,我不熟悉C 。所以,我不明白为什么ImageMap的内容无法通过clear((方法删除?
struct ImageNode
{
string key;
UIImage *image;(UIImage is a class in Objective-C)
};
struct ImagePointer
{
list<ImageNode *>::iterator it;
bool isLRUQueue;
};
list<ImageNode *> FIFOQueue;
list<ImageNode *> LRUQueue;
map<string, ImagePointer *> imageMap;
//clear method
- (void)clear
{
//why need for loop???
for (auto it = imageMap.begin(); it != imageMap.end(); it++)
{
delete *it->second->it;
delete it->second;
}
FIFOQueue.clear();
LRUQueue.clear();
imageMap.clear();
}
我不明白为什么ImageMap的内容不能被Clear((
删除
考虑,即使您确实将指针存储在列表中,也不意味着当您从列表中删除这些指针时,您要删除这些指针:
std::list<int*> l;
int i;
l.push_back(&i);
l.clear; // if list deleted the pointer contained within the list
// then bad things would happen
std::list
无法阅读您的思想,也不知道您是否要删除指针。您必须在需要删除时删除指针。清晰只能从列表中删除元素。
相关文章:
- std::map<struct,struct>::find 找不到匹配项,但是如果我循环通过 begin() 到 end(),我在那里看到匹配项
- Openssl 1.1.1d无效使用不完整的类型"struct dsa_st"
- C++Union/Struct位域的实现和可移植性
- 如何在c++中定义以struct为数据成员的类中的构造函数
- 如果 std::vector::clear() 不是静态的,如何在没有实例的情况下调用它?
- 结构体 S { int align; } 之间的区别;(struct 关键字后的名称)和 struct { int al
- struct.error:解压缩 C++ 结构时,解包需要 288 字节的缓冲区
- 错误:"Left of getValue must have class/struct/union"
- 在 SVM-Struct 中未定义对 sqrt 的引用(已使用 -lm)
- 数据类型"struct seq<0, 1, 2>{}"含义是什么?
- 在 STL 容器的 STL 容器上调用 clear
- 附加使用 Struct 作为"multikey"并将 std::vector 用作映射值的映射
- QML/C++/QObject Struct Copy
- 了解 cin.fail() 和 cin.clear语言 - Vector 追加程序
- 在 c++ 中,发生故障后是否需要 stream.clear()?
- 如何在 cpp 中解压缩数字,如果它们是使用 struct.pack(fmt, v1, v2, ..) 打包在 pyth
- 为什么不能通过在错误输入后设置 std::cin.clear() 来使用 std::cin?
- Msgpack能否提供更好的性能和与Python的struct.pack()相同的功能?
- 将向量传递给<struct> Lua 表
- 为什么具有 list<struct type>::itrator 的 struct 不能通过 clear() 删除?