About the singleton

Batfly 3 years ago updated by Frédéric Schmidt 2 years ago 1

About the singleton, I'm actually try to use this pattern in order to use the same structure for 3 .cpp functions.

Maybe it's specific to C++ (I'm a Matlab user usually and discover the other language...), so I need to understand.

I'm not really sure about this example :

     * Singletons should not be cloneable.
    Singleton(Singleton &other) = delete;
     * Singletons should not be assignable.
    void operator=(const Singleton &) = delete;

The "&other" is a variable or a C++ keyword ? I mean, Must I put the concerned variable to delete here, or "other" is enough to destroy all variable of a structure ? ^^"

At the last line here, why there are two "=" ? I don't understand this line...

Is there are an explanation and a definition of this ?

Thank you ^^


for the "&other" is for the notion of "reference". A reference it's an alias, another name, for an already existing variable.

for the last line it’s an operator overload. here it's the operator equal (the first equal).

Best Regards