Destructor is invoked during exit of scope or delete, etc. It aims to return dynamic allocated resource to the pool. When I call destructor (empty destructor) explicitly, will it / what does it do anything on class members?
It is not a question seeking help on debug, Example Code:
class Z(){
public:
Z(){ };
~Z(){ };
int count {0};
}
void main()
{
Z* z = new Z();
z->count = 1;
z->~Z();
cout << z->count << endl;
}
It seems to me that z->count stay alive after the call of destructor during my test. Calling destructor explicitly does not return the resource of object to heap. I would like to double check if it is the expected behaviour
I guess calling destructor z->~Z() directly is different to "delete z", one will only execute what implemented in ~Z(), later will do ~Z() and then delete the class members.