Pagina 1 di 1

Re: What can't a namespace do that a singleton does?

Inviato: 25 ott 2017, 21:15
da carpikes
But why not have non-member functions that share static data, declared in an unnamed namespace? And why isn't this generally suggested as a better alternative to writing a singleton class in C++?


If i've understood correctly, it's not reccomended and actually it should be avoided because otherwise you'll get the 'static initialization fiasco' ( https://isocpp.org/wiki/faq/ctors ).