@seymore15074: The choice of the container should be dependent on the usage, and the usage only. If a lot of insertions are performed in the "middle" of the sequence (obviously, this doesn't make sense for containers that aren't sequences), a vector is a bad choice. But we don't know if that is going to happen. If a random access iterator is required on the other hand, a list is a bad choice. The poster used a vector, and since I assume that he isn't completely retarded, I assume that this choice makes sense and he actually wanted a vector and not a list. If we could say anything at all, it would be a reminder of the fact that a deque provides a RAI and has a non-contiguous memory allocation strategy, thus
might be better for really large objects. But still, back insertion is performed in O(1) for both vectors and lists (a vector is a model for a
Back Insertion Sequence, after all). So if it "grows" in the right way, it isn't any less efficient than a list (except for memory efficiency, but that usually doesn't matter on modern systems. And if it does, again the deque is a "better" choice, since it behaves very much like a vector, in contrast to a list)
For consistency, I recommend storing the pointers when dealing with the STL |
Consistency with what? A container stores objects. It doesn't care if the objects are of class type or pointer type. What should be relevant in the decision should be the logical ownership relationship between container, value type and the class/object/whatever owning the container (and only this relationship). If the contained objects "die" with the container, all you do by storing pointers is introducing a new possibility for a hard-to-find bug.