当我尝试运行我的程序时,出现“map/set iterator not incrementable”错误。我读到当您使迭代器无效时会发生这种情况,但我只是在编辑迭代器指向的对象。这是正常行为吗?我能做些什么呢?如果我删除此行,则没有错误:
iterator->second.neighbour[direction] = &(find_iter->second);
完整代码:
void Gomoku::addUniqueMap( const map_Map& map_to_add )
{
this->unique_maps.push_front( map_to_add );
std::list<map_Map>::iterator map_iter = this->unique_maps.begin();
map_Iterator iterator = map_iter->begin();
for( ; iterator != map_iter->end(); ++iterator )
{
for( int i = 1, direction = 0; i > -2; --i )
{
for( int j = -1; j < 2; ++j )
{
if( iterator->second.neighbour[direction] == nullptr )
{
++direction;
continue;
}
if( i == 0 && j == 0 )
continue;
COORD pos( iterator->first.x + j, iterator->first.y + i );
wrap( pos, this->map_size );
map_Iterator find_iter = map_iter->find( pos );
if( find_iter != map_iter->end() )
{
iterator->second.neighbour[direction] = &(find_iter->second);
}
++direction;
}
}
}
}
'map_Map' - std::map<COORD, Pawn>
'map_Iterator' - std::map<COORD, Pawn>::iterator
'Pawn' -
struct Pawn
{
Pawn( Player player );
Player player;
const Pawn* neighbour[8];
};