Code:
Destructor object1( 1, "global object" );
int main()
{
cout << "\n\nENTER MAIN FUNCTION\n";
Destructor object2( 2, "local automatic" );
static Destructor object3( 3, "static object" );
create();
cout << "\nEXIT MAIN FUNCTION\n";
cin.get();
return 0;
}
void create()
{
cout << "\nCREATE FUNCTION IS CALLED" << endl;
Destructor object4( 4, "local automatic for create function" );
static Destructor object5( 5, "static object for create function" );
cout << "\nEXIT CREATE FUNCTION\n";
}
The output is:
Code:
Object 1 global object is created
MAIN FUNCTION
Object 2 local automatic is created
Object 3 static object is created
CREATE FUNCTION IS CALLED
Object 4 local automatic for create function is created
Object 5 static object for create function is created
EXIT CREATE FUNCTION
Object 4 local automatic for create function is destructed
EXIT MAIN FUNCTION
Destructors are called automatically when an object goes out of scope, I understand that the destructors are called in reverse order when the objects are created. The code above is provided by the book, the output from the book is showing that all the objects created are destructed ( displaying Object blah..blah..blah is destructed) but as you can see in my output the only object destroucted that I can explicitly see is the Object 4. Where are the others?