-2

尽管我已经在程序的每个部分都包含了 try 代码,但我无法获得导致运行时错误的行(没有任何其他详细信息):

"terminate called after throwing an instance of 'std::out_of_range'
what():  vector::_M_range_check Aborted"

我不知道我应该做什么。该错误是由以下代码引起的,因为它出现在添加这些行之后:

.....
map<int, StaticObject*>::iterator mapPos2;
vector<StaticObject*, boost::pool_allocator<StaticObject*> >::iterator vecPos;

map<int, int>::iterator mapPos = userCountMap.begin();  

mapPos2 = this->_cachedObjects.find(this->_lruQueue.at(mapPos->first)->getId());                   
vecPos = find(this->_lruQueue.begin(),this->_lruQueue.end(), this->_lruQueue.at(mapPos->first));

size -= this->_lruQueue.at(mapPos->first)->getSize();  
_availableSpace += this->_lruQueue.at(mapPos->first)->getSize(); 

delete (*mapPos2).second;   

this->_cachedObjects.erase(mapPos2); 
this->_lruQueue.erase(vecPos);  
............

后来:

map<int, int> userCountMap;

userCountMap.insert(make_pair(object->getId(),1)); ...
this->userCountMap[id]++; ...
this->userCountMap.clear(); ....
4

1 回答 1

2

std::out_of_range is thrown by std::vector::at if the index is out of range of valid values (that is, [0..size-1]).

Try wrapping the lines calling that function with try/catch blocks and see which one throws. Then, fire up your debugger and find out why the index is out of range.

于 2014-03-18T19:41:26.363 回答