我嘗試重用STL迭代器,但找不到任何關於此的信息。在這段代碼有問題: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?
迭代和反向迭代器是不同的,不相關的類型。 –