我想知道这样做的最佳方法是什么......
// 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
}
Run Code Online (Sandbox Code Playgroud)
我不认为按值传递会在这里起作用.显然我想要做的是在调用RemoveBar时保持正确的迭代器位置.通过引用是最好的选择吗?
小智 5
迭代器通常按值传递.我让RemoveBar()返回新的迭代器.
| 归档时间: |
|
| 查看次数: |
3258 次 |
| 最近记录: |