9.7. When Constructors and Destructors Are Called
Constructors and destructors are called implicitly by the compiler. The order in which these function calls occur depends on the order in which execution enters and leaves the scopes where the objects are instantiated. Generally, destructor calls are made in the reverse order of the corresponding constructor calls, but as we’ll see in Figs. 9.7–9.9, the storage classes of objects can alter the order in which destructors are called.
1 // Fig. 9.7: CreateAndDestroy.h 2 // CreateAndDestroy class definition. 3 // Member functions defined in CreateAndDestroy.cpp. 4 #include <string> 5 using namespace std; 6 7 #ifndef CREATE_H 8 #define CREATE_H 9