Search code examples
c++classinitializationdestructordestroy

Is it ok to access classes data members and perform operations on them in destructor?


I have a big concert. We know that the initialization of (non static) data members of class is performed in constructors initialization list. So calling a function, even e virtual function (this does not act as polymorphic behavior) is ok and well defined by standard.

So I wander can we do same operations of destructor? At what point classes data members or vtable are invalid or corrupted? Are there any restrictions on operations in destructor (beside throwing an exception)?

Thanks in advance.


Solution

  • At the end of your destructor's scope any remaining member variables are destroyed -- they are still alive in the destructor.