Page 1 of 1

[fixed]array erase() auto sorting?

Posted: Sun Feb 14, 2010 7:50 pm
by Virion
i've found out a problem when using array, which is for example I stored some scene nodes in an array, and would like to delete some of it later using for-loop

Code: Select all

nodeList[i]->remove();
nodeList.erase(i);
I realize scene nodes that are in the end of the list didn't get deleted. i think array auto sorted the list when i use erase(), bringing the elements at the back in-front to fill in the blank am I correct?

I don't want to do that I want to manually sort() the list after I done my removals. Any way to do that? Thanks.

Posted: Sun Feb 14, 2010 8:41 pm
by vins
Does deleting from big to lower index helps?

Posted: Sun Feb 14, 2010 8:57 pm
by Nox
:? your approach is a bit strange. If you erase something from a container it will be delete. The container just rearrange all elements. That correct. Thats not really a sort. Its more a shift operation. There is no way to "mark" some of the elements and delete it later in one big call. The only way i now is to use another container putting the kept elements in and swap the contents of the container later.

Posted: Sun Feb 14, 2010 9:31 pm
by Zeus
or you could write your own container ...

Posted: Sun Feb 14, 2010 9:57 pm
by Virion
nevermind... i cleared the array and re-add all scene nodes into the list again after deleted the unwanted scene nodes. i know, it's a bit strange but this is the only way that works for me now.

p/s. i don't know why but the reverse order just doesn't work it crashes.