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 abou
If I have something like std::vector what happens when the vector destructor is called?
It depends.
If you have a vector of values std::vector <MyClass>
, then the destructor of the vector calls the destructor for every instance of MyClass
in the vector.
If you have a vector of pointers std::vector <MyClass*>
, then you're responsible for deleting the instances of MyClass
.
What happens if I have a pointer to another class inside a class
ClassB
instance would remain in memory. Possible ways to have ClassA
destructor to make the job for you are to make B
an instance member or a smart pointer.