[英]Passing an iterator to another function
I was wondering what would be the best way to accomplish something like this... 我想知道完成这样的事情的最好方法是什么...
// 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
}
I don't think pass by value will work here. 我认为通过价值传递不会在这里起作用。 Obviously what I want to do is stay in the correct iterator position when I call RemoveBar.
显然,我要执行的操作是在调用RemoveBar时保持正确的迭代器位置。 Is pass by reference the best alternative?
通过引用传递是最好的选择吗?
Iterators are normally passed by value. 迭代器通常按值传递。 I'd make RemoveBar() return the new iterator.
我会让RemoveBar()返回新的迭代器。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.