【发布时间】:2009-12-06 20:51:06
【问题描述】:
我想知道完成这样的事情的最佳方法是什么......
// Iterating through a list
if ( foo ) {
RemoveBar( it );
}
void RemoveBar( std::list< Type >::iterator it ) {
it = listName.erase( it );
...// Other stuff related to cleaning up the removed iterator
}
我认为按值传递在这里行不通。显然,当我调用 RemoveBar 时,我想要做的是保持在正确的迭代器位置。通过引用传递是最好的选择吗?
【问题讨论】: