我尝试重用 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++) {
但出现错误:
错误:'poolbegin = std::vector<_Tp, _Alloc>::rbegin() 中的 'operator=' 不匹配,_Tp = boost::shared_ptr, _Alloc = std::allocator >'</p>
有没有办法将迭代器重置为新值?像 shared_ptr::reset 一样?