I recently changed the code to use a set instead of a vector:
std::set<b2Body *>toDestroy;
But now I'm not sure how to iterate over a set to search for objects. This is what I had:
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); }
What is equivalent now that toDestroy is a collection? Based on Objective-C, so I'm just learning the best practices in C ++.
EDIT: adding error message:
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*>]()'
source share