On 16 f?v, 14:16, "Leigh Johnston" <le...@i42.co.uk> wrote:
"requinham" <requin...@gmail.com> wrote in message
news:b31460c5-db1e-488f-a1fb-1cf1ad2f0d7f@b2g2000yqi.googlegroups.com...
Hello,
i would know if the conception of singeleton pattern define the
function who destroy the unique instance as static or not ?
because in the code of global program, this function must be the
latest function executed by the singleton and after that she will
return the handle to the main or another independant function so it's
not necessary to define this method (destroy()) as static !
Could you be more specific as there are various ways of implementing a
singleton. If you are using the Meyers Singleton then there is no need
for
a destroy function static or otherwise as the singleton is destroyed
automatically at the appropriate time during program termination.
/Leigh
thinks for all for this qwickly response :)
for the implementation, i use a simple and classic method like this :
class A {
private:
A(){};
A(const A& instance){};
~A(){};
static A* uniqueInstance=NULL;
public:
static A* getInstance(){
if (uniqueInstance==NULL)
uniqueInstance=new A();
return uniqueInstance;
}
void destroy(){
if (uniqueInstance != NULL){
delete uniqueInstance;
uniqueInstance=NULL;
}
}
is like this and normally in all the case, the destroy function is
called at the end of singleton then it's not important to make it
static
/* ... */
you should think hard if you actually need a singleton.