Possible duplicate:C ++ singleton vs fully static object
Hi,
why should I use a singleton over static class methods.
MoneyPrinter::addJob(PrinterJob &job); or MoneyPrinter::getInstance().addJob(PrinterJob &job);
Is this just a matter of style? What are you using? Why?
ps. I know that sigletones are not thread safe by default (first initialization).
The syntax gives you control over when the class is instantiated, and how DeadMG tells you if which one you want to create. A static class is less manageable and is created when main is called.
, , , - , main.
, singleton , , . ( Effective ++), , .
( - ), .
? ?
, , .
, ( " " " " ).
The general rule of singles, if you must ask, do not use it. This is true for any changeable state in the world.
It would be harder to reorganize Singleton-ness simply because of the syntax used if you are using static member functions. There is one reason.