> vector is a type of container, it is used to contain my objects, if I 
> only use vector to store "reference to object", why do I use a 'vector'?

You could still use it to get indexed access, sorting, and iterating.
I typically use vectors of pointers if I know my objects must not
move (sometimes, copying an object will defeat its semantics).

Coming back to your original question: vectors can be used to
substitute arrays. If you modify the array (i.e. re-allocate it), all
pointers into the old array will be gone. Same with vectors.

If you do not modify the vector in a certain number of ways (extending
it, etc.), the references to entries will remain valid, just as they
do in arrays.

Regards,
Martin

Reply via email to