As far as I know, I should destroy in destructors everything I created with new
and close opened filestreams and other streams.
However, I have some doubts about other objects in C++:
std::vector
andstd::string
s: Are they destroyed automatically?If I have something like
std::vector<myClass*>
of pointers to classes. What happens when the vector destructor is called?
Would it call automatically the destructor ofmyClass
? Or only the vector is destroyed but all the Objects it contains are still existant in the memory?What happens if I have a pointer to another class inside a class, say:
class A { ClassB* B; }
and Class A is destroyed at some point in the code. Will Class B be destroyed too or just the pointer and class B will be still existent somewhere in the memory?
vector<myClass*>
aremyClass*
objects, that is to say objects of pointer type. They are destroyed when the vector is destroyed, but destroying a pointer does not affect the object that the pointer points to. So the objects that the vector contains are not still existent in memory. Imagining that the objects pointed to by the pointers are "contained in the vector" is obstructing you from being able to answer your own question :-) – Steve Jessop Aug 22 '12 at 8:33add comment
links below each answer to respond to them or ask for clarification. Don't use thePost Your Answer
link! – Rook Aug 22 '12 at 9:01