deconstructing with a vector
I have created a vector of objects that I am constantly changing, but I want to have a deconstructor to deallocate a string in each of the objects when I am done using the vector. I wrote a deconstructor but I noticed that it is getting called all over the place- even when I am not done using the memory. Is there something special about vectors that can account for this, and if so how do I deallocate the memory used in the string for each object in a vector?
Any suggestions would be great!
Is the vector on the heap?
if your vector was newed from the beginning you can deallocate it with delete. If not it will be deallocated when it runs out of scope. The vector will of course delete it's objects before it deletes itself, that is handled in the vectors destructor.