//: C10:StaticDestructors.cpp
// From Thinking in C++, 2nd Edition
// Available at http://www.BruceEckel.com
// (c) Bruce Eckel 2000
// Copyright notice in Copyright.txt
// Static object destructors

#include <iostream>
using namespace std;

class Obj
{

char c;
/* Identifier */

public:

Obj(char cc) : c(cc)
{

cout << "Obj::Obj() for " << c << endl;

}
~Obj()
{

cout << "Obj::~Obj() for " << c << endl;

}

};

Obj a('a');
/* Global (static storage) */

/* Constructor & destructor always called */

void f()
{

static Obj b('b');

}

void g()
{

static Obj c('c');

}

/* Il costruttore per "a", viene eseguito prima del "main" (essendo dichiarata globalmente), mentre il costruttore per "b", viene eseguito all'interno della funzione "f() che viene chiamata dal "main".*/

int main()
{

cout << "inside main()" << endl;
f();
/* Calls static constructor for b */

/* g() not called */

/* In questo caso, il costruttore per l'oggetto "c" non viene mai eseguito. */


cout << "leaving main()" << endl;

} ///:~