我尝试重用 STL 迭代器,但找不到任何相关信息。这段代码有问题:
std::vector< boost::shared_ptr<Connection> >::iterator poolbegin = pool.begin();
std::vector< boost::shared_ptr<Connection> >::iterator poolend = pool.end();
if( order ) {
poolbegin = pool.rbegin(); // Here compilation fails
poolend = pool.rend();
}
for( std::vector< boost::shared_ptr<Connection> >::iterator it = poolbegin; it<poolend; it++) {
但是出现错误:
error: no match for ‘operator=’ in ‘poolbegin = std::vector<_Tp, _Alloc>::rbegin() with _Tp = boost::shared_ptr, _Alloc = std::allocator >’
有没有办法将迭代器重置为新值?喜欢 shared_ptr::reset 吗?
最佳答案
rbegin()
返回一个 reverse_iterator
,它是与普通 iterator
完全不同的类型。
它们不能相互赋值。
关于c++ - STL迭代器重置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12605080/