Not asking about singletons here (nor advocating). With that clarified:
If we assume someone wants a global + unique object, why isn't a namespace always the preferred approach in C++, over implementing a singleton class?
I've only seen the namespace approach encouraged when there aren't statics being shared. Eg; from Google's style guidelines:
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++?
↧