Quantcast
Channel: GameDev.net
Viewing all articles
Browse latest Browse all 17825

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

$
0
0
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++?

Viewing all articles
Browse latest Browse all 17825

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>