Click here to Skip to main content
15,916,188 members
Home / Discussions / ATL / WTL / STL
   

ATL / WTL / STL

 
GeneralSTL question. Pin
WREY9-Nov-03 10:03
WREY9-Nov-03 10:03 
GeneralRe: STL question. Pin
Christian Graus9-Nov-03 10:16
protectorChristian Graus9-Nov-03 10:16 
GeneralRe: STL question. Pin
WREY9-Nov-03 12:11
WREY9-Nov-03 12:11 
GeneralRe: STL question. Pin
ZoogieZork9-Nov-03 13:52
ZoogieZork9-Nov-03 13:52 
GeneralRe: STL question. Pin
WREY9-Nov-03 17:36
WREY9-Nov-03 17:36 
GeneralRe: STL question. Pin
jbarton10-Nov-03 7:25
jbarton10-Nov-03 7:25 
GeneralRe: STL question. Pin
WREY10-Nov-03 7:54
WREY10-Nov-03 7:54 
GeneralRe: STL question. Pin
jbarton11-Nov-03 4:42
jbarton11-Nov-03 4:42 
When I look at a class like MyClass (in your original post), I would assume that the lifetime of the vector would be the same as the lifetime of the object that contains it. I would control when the vector gets destroyed by controlling the lifetime of the MyClass object, rather than getting a pointer to the vector out of the object.

Similarly, I would assume that the lifetime of the vector inside an OtherClass object should be the same as the object containing it.

For both of these objects, this seemed to be the case, as you were allocating the vector in the constructor of the object. You didn't show a destructor, so I couldn't tell whether you intended to keep the vector after destroying the object.

You might want to rethink this, as it seems that the ownership of the vectors really belong to the objects that contain the pointers.

I don't know what your intentions are, so I am not sure which way I would change this. ( Of course, you can just leave it the way it is... I am just giving my opinion Smile | :) )

If you intend MyClass to be a class that initializes a vector of OtherClass objects, but does not have anything to do with the vector afterwards, I would probably pass a reference to the vector to the constructor of the MyClass object. The ownership of the vector would then be outside of the MyClass object. The vector would persist because it would be declared at a higher level, and passed in to the MyClass object for initialization. The vector object could be declared as high level as you need it to persist, and could be passed by reference to the various routines that need it.

If you intend MyClass to be a class that is a vector of OtherClass objects, I would keep the actual vector inside the object (not a pointer), and make sure that the MyClass object persists (by either declaring it at a high enough level that it remains in scope, or by allocating a MyClass object with new). I personally would lean this way, as I could then add routines to manipulate the vector to the MyClass object.

Best regards,
John
Generalofstream position and >2GB files Pin
Jeremy Osner7-Nov-03 3:38
Jeremy Osner7-Nov-03 3:38 
GeneralRe: ofstream position and >2GB files Pin
Christian Graus9-Nov-03 10:17
protectorChristian Graus9-Nov-03 10:17 
GeneralRe: ofstream position and >2GB files Pin
Jeremy Osner9-Nov-03 15:50
Jeremy Osner9-Nov-03 15:50 
GeneralTrue C/C++ goodies Pin
TW7-Nov-03 2:01
TW7-Nov-03 2:01 
GeneralSome Problem in Connection Points (MultiClients) Pin
shudingbo7-Nov-03 1:47
shudingbo7-Nov-03 1:47 
QuestionWhere is <Developers Workshop to COM and ATL 3.0 >? Pin
cr9996-Nov-03 17:55
cr9996-Nov-03 17:55 
GeneralATL/WTL DLL and the CMessageLoop* pLoop Pin
bryces6-Nov-03 13:38
bryces6-Nov-03 13:38 
GeneralRe: ATL/WTL DLL and the CMessageLoop* pLoop Pin
Michael Dunn6-Nov-03 16:51
sitebuilderMichael Dunn6-Nov-03 16:51 
Generalmultithreading deque<> question Pin
wibbik6-Nov-03 4:41
wibbik6-Nov-03 4:41 
GeneralRe: multithreading deque<> question Pin
geo_m6-Nov-03 5:26
geo_m6-Nov-03 5:26 
GeneralRe: multithreading deque<> question Pin
valikac6-Nov-03 5:51
valikac6-Nov-03 5:51 
GeneralRe: multithreading deque<> question Pin
Jeff Varszegi6-Nov-03 6:47
professionalJeff Varszegi6-Nov-03 6:47 
GeneralRe: multithreading deque<> question Pin
wibbik6-Nov-03 20:20
wibbik6-Nov-03 20:20 
GeneralRe: multithreading deque<> question Pin
Giles9-Nov-03 10:55
Giles9-Nov-03 10:55 
GeneralLinker error for vtMissing Pin
nigs_krec6-Nov-03 2:32
nigs_krec6-Nov-03 2:32 
GeneralRe: Linker error for vtMissing Pin
Brian Shifrin6-Nov-03 7:47
Brian Shifrin6-Nov-03 7:47 
General<vector> question Pin
Steve Messer5-Nov-03 7:02
Steve Messer5-Nov-03 7:02 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.