Cocos2d-x Vector——vector iterators incompatible
***************************************转载请注明出处:http://blog.csdn.net/lttree******************************************
使用 cocos2d-x 中的 Vector的时候,
在删除某个对象的时候出现了个错误,非常崩溃啊.....
Vector<Bullet*>* bullets; // 遍历每一个bullet,让他们自己更新
for ( auto it = bullets->begin();it!=bullets->end();it++)
{
(*it)->update(); // 获取子弹生命。若子弹已经消亡,释放
if( (*it)->getLife() ) { Bubblet* b = *it; bubblets->eraseObject(b);
this->removeChild( b,true );
} }
就会错误发生——vector iterators incompatible。
也许是我 打开的方式不正确。于是用C++11方法:
Vector<Bullet*> bullets;
for( auto& b : bullets ) {
b->update();
if( b->getLife() ) {
bubblets.eraseObject(b);
this->removeChild(b,true);
}
}
还是不行。。。
找了非常久,发现,
据说是由于,迭代器遍历的时候。假设把当前的给删除了,那么后面就乱套了,无法继续进行下去了,
所以。会崩溃。
于是乎。假设通过迭代器来遍历,就这么改:
// 遍历每一个bullet。让他们自己更新
for ( auto it = bullets->begin();it!=bullets->end();)
{
(*it)->update(); // 获取子弹生命,若子弹已经消亡,释放
if( (*it)->getLife() ) { Bubblet* b = *it; it = bubblets->eraseObject(b);
this->removeChild( b,true );
}
else {
it++;
} }
迭代器的移动,不再靠循环。而是靠推断语句。
可惜。通过C++11方法的遍历,我还没想到要怎么改。。。
***************************************转载请注明出处:http://blog.csdn.net/lttree******************************************
Cocos2d-x Vector——vector iterators incompatible的更多相关文章
- Solve Error Debug Assertion Failed Expression vector iterators incompatible Using PCL in Release Mode of VS2010
When using PCL 1.4.0 in the release mode building under VS2010, we might sometime get the error &quo ...
- vector iterators incompatible
字面翻译迭代器类型不兼容 今天同事遇到的这个问题算是一个习惯性写法的问题.描述一下代码: struct Track{}; class BaseTrack { - std::vector<Trac ...
- vector::erase returns incompatible iterator in debug build
关于std::vector中erase的用法http://www.cplusplus.com/reference/vector/vector/erase/ #include <vector> ...
- (原)使用vectot的.end()报错:iterators incompatible
转载请注明出处: http://www.cnblogs.com/darkknightzh/p/5070672.html 参考网址: http://blog.csdn.net/yxnyxnyxnyxny ...
- vector< vector<int> >类似于二维数组
vector< vector<int> > intVV; vector<int> intV; int i,j; ;i<;++i){ intV.clear(); ...
- NDK GDB 中打印vector , vector<vector <> >
在android上进行native开发的时候,我们需要用NDK-GDB 对native code进行调试,其中很麻烦的是,我使用的NDK版本是4.0,该版本还不支持用NDK-GDB直接打印vector ...
- 对多维向量vector<vector<int> > vec进行操作
直接写作vector<vector<int> > vec在VC++6.0下编译不过改做: typedef std::vector<int> ROW; s ...
- 2016.6.24——vector<vector<int>>【Binary Tree Level Order Traversal】
Binary Tree Level Order Traversal 本题收获: 1.vector<vector<int>>的用法 vector<vector<int ...
- vector vector int 初始化
方法一: vector<vector<int>>array=(2,vector<int>()); array[0].push_back(1); array[i].p ...
随机推荐
- 15,re正则表达式
判断手机号是否合法. phone_number = input('请输入手机号:') if re.match('^(13|14|15|18)[0-9]{9}$',phone_number): prin ...
- 用Go编写的本地文件服务器
本文来自网易云社区,转载务必请注明出处. 一.前言 一切问题的起源就是来自一个问题"为什么我打的jar包没有注解?",带着这个疑问查了一圈资料,原来问题主要是在没有将源码中的注释进 ...
- swift写一个简单的列表unable to dequeue a cell with identifier reuseIdentifier - must register a nib or a cla
报错:unable to dequeue a cell with identifier reuseIdentifier - must register a nib or a class for the ...
- Wp8无广告 锁屏可以持续用的手电筒
前面的博文写了怎么实现手电筒,界面不够漂亮 我修改了界面之后 提交到了微软的App商店 在这里送上下载地址: http://www.windowsphone.com/zh-cn/store/app/% ...
- Yii2.0 添加分类category model类
<?php namespace app\models; use yii\db\ActiveRecord; use Yii; use yii\helpers\ArrayHelper; class ...
- NYOJ 293 Sticks
Sticks 时间限制:3000 ms | 内存限制:65535 KB 难度:5 描述 George took sticks of the same length and cut them r ...
- hdu_2070_Fibbonacci Number
这个题我用long long ,printf("%lld");输出就错误了 我用__int64,printf("%I64d");输出就正确了 这点需要注意. # ...
- HDU-1392 Surround the Trees,凸包入门!
Surround the Trees 此题讨论区里大喊有坑,原谅我没有仔细读题还跳过了坑点. 题意:平面上有n棵树,选一些树用绳子围成一个包围圈,使得所有的树都在这个圈内. 思路:简单凸包入门题,凸包 ...
- 性能测试之五--webservices接口测试
下面我们进行webservices接口的讲解,包括脚本生成,参数化和关联. 以天气预报的接口为例,接口地址为: http://ws.webxml.com.cn/WebServices/WeatherW ...
- [BZOJ4993||4990] [Usaco2017 Feb]Why Did the Cow Cross the Road II(DP + 线段树)
传送门 f[i][j]表示当前第i个,且最后一个位置连接到j 第一维可以省去,能连边的点可以预处理出来,dp可以用线段树优化 #include <cstdio> #include < ...