Why use iterators instead of array indices?

前端 未结 27 1880
萌比男神i
萌比男神i 2020-11-22 15:45

Take the following two lines of code:

for (int i = 0; i < some_vector.size(); i++)
{
    //do stuff
}

And this:

for (som         


        
27条回答
  •  心在旅途
    2020-11-22 16:22

    I always use array index because many application of mine require something like "display thumbnail image". So I wrote something like this:

    some_vector[0].left=0;
    some_vector[0].top =0;
    for (int i = 1; i < some_vector.size(); i++) { some_vector[i].left = some_vector[i-1].width + some_vector[i-1].left; if(i % 6 ==0) { some_vector[i].top = some_vector[i].top.height + some_vector[i].top; some_vector[i].left = 0; } }

提交回复
热议问题