PDA

View Full Version : vector of objects



mickey
7th May 2006, 17:29
Hi I need an hint; I need a vector of an object myObj; its size are from 1 to 8; but I should must delete object also; so I'm thinking to use vector <myObj> obj; but its use is that: I must delete object in evey position of vector (ie elemet 4 and not destroy 5,6,7,8). Furthermore I need to know the index of element; Do I use a map? What's better for this?
Thanks

wysota
7th May 2006, 18:19
If you don't require indexes of element to be constant, you can use a vector or a list (if you think you'll be removing elements from the middle very often, it's better to use a list). Otherwise use a map.

brcain
8th May 2006, 21:13
You might also consider the std::deque. It has better performance than the std::vector ... especially with deletions ... and still maintains the indexing capability that you lose with std::list.

You could use the std::map, but I wouldn't if all you need is an indexing capability.