What the destructor has to do directly follows from the state of the class and design. Thus, the choice is subtle. You can do this in a strict expression or call a function. I see no reason why not to call a function, especially if other member functions can also use it. (See Implementing smart pointers having a reset() function ...)
You say that if the work is difficult, we better not do it. Hmmm. Or does the idea just not do it in dtor, but leave this obligation to the programmer? How to return to C? Assuming that the most attractive feature of C ++ has dtors that allow RAII?
The only thing to do in dtor is to grasp the exceptions. With some luck, they naturally cannot happen. If there is a chance, itβs really nice to have some kind of social function to carry out most of the tasks from which to quit - an honest game. (Ie CFile class closes the file in dtor if it is still open. When used for the output file, you must close it manually and deal with possible errors, such as the inability to flush the last buffers to a full disk. All this and dtor will be freed from hard work .
source share