Is it possible to complete software execution without missing calls to destructors? For example, in the code below, the destructor for test will never be called due to the exit(1) statement.
#include <iostream>
What I need is a way to end the program (from inside func() ), which calls all the necessary destructors before exiting. So far, I have been handling this through the func() return value, as in:
bool func() { //Assuming something went wrong: return false; } int main(int argc, char *argv[]) { A test; if( !func() )return 1; return 0; }
The problem with this method is that it quickly becomes very annoying (and the code swells) to control when you need to apply it to a series of nested functions.
Is there a way to achieve the same results of the second example (correct calls to the destructor) with syntax similar to the first example (calling exit(1) wherever you are)?
Malabarba
source share