Class Destructors

I was a bit doubtful about how do Destructors work.
Can someone please explain what do they actually do.
http://www.cplusplus.com/doc/tutorial/classes/

Destructors are just functions called after the class is destroyed. They are used to delete some pointers or save data when the user exits.
Also worth mentioning is that Destructors are called at the end of the scope of the object they belong to, in some cases this is when the object is deleted or has it's Destructor called explicitly. But keep in mind that if the objects scope is not global and they are not declared static, then the destructor will be called for each instance of an object when the function it is declared in finishes.

Normally this is not an issue, but you should keep it in mind so that you don't try to do whacky things like close a shared file stream in an objects destructor or otherwise try to cleanup variables that are not part of the object (I recently caught myself doing this in an earlier project).
Topic archived. No new replies allowed.