哪种遍历效率高些?

1,_boxSprites = new CCMutableArray<CCSprite *>();
CCMutableArray<CCSprite *>::CCMutableArrayIterator boxIterator;
for (boxIterator = _boxSprites->begin(); boxIterator != _boxSprites->end(); boxIterator++){
CCSprite *box = (CCSprite *)*boxIterator;
}

2,_boxSprites = new CCMutableArray<CCSprite *>();
for(int i = 0;i < _boxSprites->count();i++){
CCSprite *box = (CCSprite *)_boxSprites->getObjectAtIndex(i);
}

_boxSprites->count()要写到循环外面,很耗的.这样效率应该就是对待了.都是std::vector

谢谢。:lol

理论上for each会比其他遍历效率要高

有个CCARRAY_FOREARCH

怎么不试试 std::for_each
C++支持lambda表达式之后空前的好用

— Begin quote from ____

Zealot 发表于 2012-11-6 18:03 url

怎么不试试 std::for_each
C++支持lambda表达式之后空前的好用

— End quote

只需要这样:
std::for_each(_boxSprites->begin(), _boxSprites->end(), ](CCSprite *sprite){
CCSprite *box = sprite;
});

java 1.5 版还是 1.6版 支持 for - each语法,。不知道 C++ 有没有