【发布时间】:2011-07-08 08:22:09
【问题描述】:
我最近更改了一些代码以使用集合而不是向量:
std::set<b2Body *>toDestroy;
//std::vector<b2Body *>toDestroy;
但现在我不确定如何迭代集合以查找对象。这就是我所拥有的:
std::vector<b2Body *>::iterator pos2;
for(pos2 = toDestroy.begin(); pos2 != toDestroy.end(); ++pos2) {
b2Body *body = *pos2;
if (body->GetUserData() != NULL) {
CCSprite *sprite = (CCSprite *) body->GetUserData();
[self removeChild:sprite cleanup:YES];
}
_world->DestroyBody(body);
}
既然 toDestroy 是一个集合,那么等价于什么?来自 Objective-C,所以我只是在学习 C++ 的最佳实践。
编辑:添加我得到的错误消息:
error: no match for 'operator=' in 'pos2 = toDestroy. std::set<_Key, _Compare, _Alloc>::begin [with _Key = b2Body*, _Compare = std::less<b2Body*>, _Alloc = std::allocator<b2Body*>]()'
【问题讨论】:
-
这与是否重复有什么关系?