Operating System - OpenVMS
Showing results for 
Search instead for 
Did you mean: 

pointer in stl vector?

Bassel Salhab
Occasional Visitor

pointer in stl vector?


I want to use the STL container class "vector" and I want to store in it objects of a specific type that I have created. Is it better to store pointers to my objects inside the vector or is it better to store the objects themselves?

Ian Miller.
Honored Contributor

Re: pointer in stl vector?

Bessel, Welcome to the hp itrc VMS Forum. What version of VMS and what version of the C++ compiler are you using?
Purely Personal Opinion
Bojan Nemec
Honored Contributor

Re: pointer in stl vector?


First, welcome to the VMS forum.

Store pointers or objects, depends on yours implementation. You must know that, when you store an object in the vector, you realy store a copy of the object (the copy constructor CLASS (const CLASS &) is called) and when you remove an object in the midle of the vector the copy assignement operator (CLASS & operator = (const CLASS &))is called for objects which are stored after the removed object. If you store the same object more times in a vector or store the object in two different vectors, these are not the same objects, but copyes of the object.
(CLASS is meant as yours class)

When working with pointers, only pointers are moved and they always point to the same object.