fonctionnement de la classe Singleton
//quelqu'un pourrait-il m'expliquer pourquoi les destructeurs de
//MonObjet et Singleton ne
//sont pas appelés.
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
|
class MonObjet
{
public:
MonObjet() {
std::cout<<"construction de MonObjet"<<std::endl;
}
~MonObjet () {
std::cout<<"destruction de MonObjet"<<std::endl;
}
};
class Singleton
{
public :
Singleton()
{
std::cout<<"appel constructeur"<<std::endl;
};
~Singleton()
{
std::cout<<"appel du destructeur"<<std::endl;
}
static Singleton * pt;
static Singleton * Instance()
{
if ( !pt) pt = new Singleton;
return pt;
}
MonObjet titi;
};
Singleton * Singleton::pt = 0;
int _tmain(int argc, _TCHAR* argv[])
{
Singleton::Instance();
return 0;
} |
d'avance merci