Operating System - OpenVMS
1827849 Members
1858 Online
109969 Solutions
New Discussion

Re: pointer in stl vector?

 
Bassel Salhab
New Member

pointer in stl vector?

Hello,

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?

thanx
2 REPLIES 2
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?

Bassel,

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.

Bojan