【发布时间】:2012-09-26 15:21:01
【问题描述】:
我尝试重用 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() with _Tp = boost::shared_ptr, _Alloc = std::allocator >'
有没有办法将迭代器重置为新值?喜欢 shared_ptr::reset 吗?
【问题讨论】:
-
迭代器和反向迭代器是不同的、不相关的类型。