On Apr 21, 2:30 am, "barcaroller" <barcarol...@music.netwrote:
Quote:
|
"Ian Collins" <ian-n...@hotmail.comwrote in message
|
Quote:
|
news:58t3hhF2i6eqtU23@mid.individual.net...
|
Quote:
Quote:
barcaroller wrote: Quote:
When a STL container is destroyed, will the destructor of the individual
objects be automatically called?
| | |
Quote:
Quote: |
Yes, assuming they have one!
| |
(Formally, all objects have destructors. Some destructors are
trivial, however.)
Quote:
|
Does this also apply to object pointers (e.g. set<Class*>)?
|
Of course. The pointer gets destroyed. (Of course, the
destructor of a pointer is trivial, so nothing much really
happens.)
The library does not persue pointers. Luckily, because in a lot
of cases, the set<Class*is used for navigation, and there are
still a lot of other pointers to the objects when the set gets
destructed.
Quote:
In this case I
would create the object myself (using 'new Class') but I assume that, since
I created it, I should destroy it.
|
Correct.
Quote:
However, there's no reason why the STL
container could not do that for me (by calling delete for each object).
Would it?
|
Only that it would break most common uses of sets of pointers.
It's really fairly rare for a container to have ownership of a
non-value object.
--
James Kanze (Gabi Software) email:
james.kanze@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34