PDA

View Full Version : [SOLVED] Quick C++ vector question



kahumba
February 10th, 2010, 03:28 PM
Hi,
Trying to properly clean up a vector which contains pointers to a class "File".
The site at
http://www.cplusplus.com/reference/stl/vector/clear/
says the vector method "clear()" before removing its elements calls their destructors, however in my case their destructors don't get called.

Is that cause I'm using pointers to elements instead of elements or is it something else?

SledgeHammer_999
February 10th, 2010, 03:32 PM
Is that cause I'm using pointers to elements instead of elements or is it something else?

Yes. The "element" the vector holds is a pointer-to-object not the object itself. You have to manually "delete" each pointer before clear()

kahumba
February 10th, 2010, 03:36 PM
thanks