【发布时间】:2014-08-03 15:13:33
【问题描述】:
我试图在列表中返回一个值,然后将其从列表中删除,但不删除其内容。但是当我调用list.erase 时,这个函数会调用项目的析构函数。所以项目被删除后temp的内容也被销毁了。如何保留temp的内容?
Vertice *temp = NULL;
//Remove da lista o vértice escolhido para iniciar a busca.
for (list<Vertice>::iterator it = lista.begin(); it != lista.end(); it++) {
if (it->getId() == (v)) {
temp = &*it;
lista.erase(it);
break;
}
}
【问题讨论】:
-
顶点的单数是“顶点”。
-
@Lightness 英语是的,但不是葡萄牙语,这似乎是代码的主要语言。
标签: c++ list destructor erase