ssssstatttticccc
-
Hallo!
Ich hape eine Klass mit dynamischer Speicherplatzverwaltung in einer Funktion als static angegeben. Wird nun der Destruktor beim Beenden des Programms aufgerufen, oder nicht?
-
Wird nun der Destruktor beim Beenden des Programms aufgerufen, oder nicht?
Sicher. Solange das Programm ordnungsgemäß beendet wird, wird auch der Dtor statischer Objekte aufgerufen.
-
Werden bei diesem exit() Befehl auch alle Destruktoren der statischen Objekte aufgerufen? Was passiert bei diesem Befehl eigentlich genau?
-
Ja, aber nur die Destruktoren statischer, nicht die automatischer Objekte.
exit(int status) 4 The function exit() has additional behavior in this International Standard: --First, objects with static storage duration are destroyed and func- tions registered by calling atexit are called. Objects with static storage duration are destroyed in the reverse order of the comple- tion of their constructor. (Automatic objects are not destroyed as a result of calling exit().)28) Functions registered with atexit are called in the reverse order of their registration.29) A function registered with atexit before an object obj1 of static storage dura- tion is initialized will not be called until obj1's destruction has completed. A function registered with atexit after an object obj2 of static storage duration is initialized will be called before obj2's destruction starts. _________________________ 28) Objects with automatic storage duration are all destroyed in a program whose function main() contains no automatic objects and exe- cutes the call to exit(). Control can be transferred directly to such a main() by throwing an exception that is caught in main(). 29) A function is called for every time it is registered. --Next, all open C streams (as mediated by the function signatures declared in <cstdio> ) with unwritten buffered data are flushed, all open C streams are closed, and all files created by calling tmp- file() are removed.30) --Finally, control is returned to the host environment. If status is zero or EXIT_SUCCESS, an implementation-defined form of the status successful termination is returned. If status is EXIT_FAILURE, an implementation-defined form of the status unsuccessful termination is returned. Otherwise the status returned is implementation-defined.31) 5 The function exit() never returns to its caller.