When you say that class members are deleted in the destructor, you must distinguish between members that are not pointers and those that are. Let's say you have a class like this:
class Foo { public: Foo() {p = new int;} ~Foo(){} private: int a; int *p; };
This class has 2 data elements: an integer a and a pointer to an integer p . When the destructor is called, the object is destroyed, which means that the destructors for all its members are called. This happens even if the body of the destructor is empty. In the case of a primitive type, such as an integer, a call to its destructor means that the memory it occupies will be released. However, when you destroy a pointer, there is a catch: everything that it points to is not destroyed by default. To do this, you must explicitly call delete .
Thus, in our example, a will be destroyed when the destructor is called, and there will be p , but not everything that p points to. If you want to free the memory for which p indicates, the destructor for Foo should look like this:
~Foo() {delete p};
So, back to your question, all members of your class that are not pointers will be destroyed regardless of when the object's destructor is called. On the other hand, if you have members that are pointers, then what they point to will not be destroyed unless you specifically name delete for them in the destructor.
Dima
source share