首页 \ 问答 \ map迭代器不可递增(map iterator not incrementable)

map迭代器不可递增(map iterator not incrementable)

当我尝试运行我的程序时,我得到'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
'典当' -

struct Pawn
{
    Pawn( Player player );
    Player      player;
    const Pawn* neighbour[8];
};

When I try to run my program I get 'map/set iterator not incrementable' error. I read that it happens when you invalidate iterator, but I'm only editing objects pointed by iterator. Is this normal behaviour? What can I do about it? If I delete this line then there is no error:

iterator->second.neighbour[direction] = &(find_iter->second);

Full code:

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];
};

原文:https://stackoverflow.com/questions/15765092
更新时间:2019-12-13 08:38

最满意答案

错误的原因是我正在访问和修改neighbour[8] ,所以我正在修改out数组范围的元素,并且可能它已经对迭代器做了一些事情。
在Debug版本中,我得到了map/set iterator not incrementable错误,而在Release版本中,迭代器无法递增,导致程序无限循环。


The cause of the error was that I was accessing and modifying neighbour[8], so I was modifying element of out array range and possibly it has done something to the iterator.
In Debug version I got map/set iterator not incrementable error while in Release version iterator couldn't be incremented and it caused program to loop infinitely.

2013-04-03

相关问答

更多

MVC4:ViewModel(带有radiobuttonlist)在HttpPost之后为空(MVC4: ViewModel (with radiobuttonlist) is empty after HttpPost)

我没有看到表单有如下ID的映射: @Html.HiddenFor(model => model.Id) 每个内部问题集合也应该具有Id,以便与表单一起发布。 因此,对于您可以拥有的每个问题,在表单的foreach循环中: @Html.HiddenFor(model => item.Question.Id) 该模型还具有MultipleChoiceQuestion类型的集合。 对于模型绑定到集合,集合元素的名称应具有带有序数字的name属性,如本文http://haacked.com/arch

通过类传递布尔值(Pass Boolean through classes)

你可以把它变成一个静态变量。 您需要将其称为“AvoiderGame.mute”,而不是在拥有类内部。 //declaration in AvoiderGame public static var mute:Boolean; //use in some other file AvoiderGame.mute = (true | false); 但这被认为是一种不好的做法。 我建议查找如何创建一个简单的声音管理器类来处理这种类型的全局变量。 尝试搜索:“声音管理器as3”,“单例模式as3”

从Scala的HashMap.mapValues中获取HashMap?(Getting a HashMap from Scala's HashMap.mapValues?)

您可以使用scala集合内置的groupBy函数,而不是使用可变的HashMap来构建Map 。 这将创建一个从分组属性到该组中值的列表的映射,然后可以聚合,例如通过获取总和: def percentages: Map[String, Double] = { val t = total quantities.groupBy(_.name).mapValues(_.map(_.amount).sum / t) } 此管道转换您的List[Quantity] => Map[String

API返回错误:错误:未设置访问或刷新令牌(The API returned an error: Error: No access or refresh token is set)

可悲的是,我正在进行2部分注册。 第一个过去,我正在设置令牌。 当用户提供新的详细信息再次提交页面时,当我打电话给谷歌时,我没有设置令牌。 Sadly, I was doing a 2 part registration. The first past, I was setting the token. When the page was submitted again with new details from the user, when I was making the call to g

如果我按相反的移动键,播放器停止(as3 if i press opposite movement keys, player stops)

设置isUp=false时,应设置isUp=false 。 反之亦然。 现在你正在做的就是将事情设置为真,但是当一个人变为真时你应该将其他人设置为假。 另外,检查if(isDown)是否足以满足布尔属性 希望这可以帮助。 You should set isUp=false when setting isDown=true. And vice versa. Right now all you are doing is setting things as true, but you should s

获取急切懒惰的定义关系(Fetch eagerly lazy defined relations)

您可以使用CriteriaApi连接(如果使用CriteriaApi进行查询构建)或在JPQL情况下使用JOIN FETCH强制加载所选属性。 Google提供了很多关于操作方法的示例。 这是其中之一 You can force eager load of selected properties using CriteriaApi joins (if using CriteriaApi for query building) or JOIN FETCH in case of JPQL. Goog

如何从Python 3脚本中找到Python 2解释器路径?(How to find Python 2 interpreter path from Python 3 script?)

使用os.get_exec_path() (可从3.2获得)获取将搜索可执行文件的目录列表。 In [1]: import os In [2]: paths = os.get_exec_path() In [5]: for p in paths: ...: for prog in ["python2", "python2.exe"]: ...: attempt = os.path.join(p, prog) ...: if os.pa

使用django-rest-framework获取模型的随机对象(Getting random object of a model with django-rest-framework)

正如@CarltonGibson注意到的, queryset是RandomObject类的一个属性。 因此它缓存,以后不能更改。 因此,如果要在某些APIView创建一些可更改的查询集(如在每个请求中获取随机对象),则必须覆盖get_queryset()方法。 而不是 class RandomObject(generics.ListAPIView): queryset = MyModel.objects.all().filter(id = pick_random_object())

相关文章

更多

最新问答

更多
  • jsPlumb draggable element javascript函数(jsPlumb draggable element javascript function)
  • MVC4:ViewModel(带有radiobuttonlist)在HttpPost之后为空(MVC4: ViewModel (with radiobuttonlist) is empty after HttpPost)
  • 如何在同一帐户上设置“Dev repo”(在prod和团队之间)(How to set up a “Dev repo” (between the prod and the team) on the same account)
  • 如何在tcl中将eth0配置为发送方udp端口(how to configure eth0 as a sender udp port in tcl)
  • 在main方法中进行更改后传递给构造函数的TreeMap实例的行为是什么(What is the behavior of a TreeMap instance passed into a constructor following changes in main method)
  • 在这个的一些属性不同的颜色(Different color in some properties of this)
  • CURL没有返回任何内容(CURL Not returning anything)
  • MVC5注入依赖于城堡windsor的视图(MVC5 injecting dependency on a view with castle windsor)
  • CakePHP AJAX-Call:发生错误:未定义(CakePHP AJAX-Call: An error occured: undefined)
  • 如何用.aidl扩展名创建文件?(how to create a file with .aidl extension?)
  • 无法获得全尺寸动态WordPress灯箱图像显示(Cannot get full size dynamic WordPress lightbox image to display)
  • 使用Jsoup删除元素不起作用(Removing Element with Jsoup doesn't work)
  • 交叉编译ARM的MongoDB C ++驱动程序。(Cross compiling MongoDB C++ driver for ARM. Cannot find Boost Libraries)
  • ProgressDialog没有关闭(ProgressDialog not closing)
  • 单元测试DB中的JPA插入(Unit testing JPA insertion in the DB)
  • 点击谷歌服务对话框中的更新按钮(Click on update button in check google service dialog)
  • 适用于PhoneGap Build的iOS“缺少必需的57x57图标”(“Missing required 57x57 icon” for iOS on PhoneGap Build)
  • MVC ckeditor post编辑器值内联(MVC ckeditor post editor value inline)
  • Angular 2 Pipe - 无法读取未定义的属性'toString'(Angular 2 Pipe - Cannot read property 'toString' of undefined)
  • 安装引导加载程序(Installing bootloaders)
  • 用于确定最终如何包含头文件的工具(Tool to figure out how a header file is eventually being included)
  • 在将字符串转换为int [duplicate]之前检查字符串是否不是数字(Check if string is not a number before converting it to a int [duplicate])
  • 从脚本构建db2数据库以进行构建验证的工具?(Tools to build db2 database from scripts for build verification?)
  • 在偏移之后向FileOutputStream写一个数字(Write a number to FileOutputStream after an offset)
  • Javascript RegEx仅限数字(无特殊字符)(Javascript RegEx for Numbers Only (no special characters))
  • 我可以在PHP的Linux服务器上运行新的COM(“WScript.Shell”)(Can I run new COM(“WScript.Shell”) on linux servers in PHP)
  • 在Backbone.js中放置与视图不直接相关的代码(例如广告,分析等)的位置?(Where to place code not directly related to a view (such as ads, analytics etc) in Backbone.js?)
  • 适用于Mac和PC的一般开发人员必备软件综合列表[关闭](Comprehensive List of Essential Software for General Developers on Mac and PC [closed])
  • 将语言文本转换为模型(Transformation Language Text to Model)
  • 在控制器中的两个方法之间共享变量?(Sharing variables between two methods in a controller?)