4 ms·
This is wrong for reasons given here: http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml#Static_and_Global_Variables http://google-styleguide.google
by pfedor 14y ago
This is wrong for reasons given here: http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml#Static_and_Global_Variables http://google-styleguide.googlecode.com/svn/trunk/cppguide.x...
- pmelendez 14y agoI am not sure if that applies here... Static objects introduce hard to find bugs because you can't figure out the order of instantiation... Over here there is just one unique instance so you know exactly where it was instantiated.
- pfedor 14y agoBut that unique instance is presumably referenced by other objects which may want to use it as part of their own shut down logic, at which point it might no longer exist. (And things get only worse in the presence of threads.)
- deleted 14y ago[deleted]
- pmelendez 14y agoSorry I read it again (the first time I was reading it on my phone) and I thought we were discussing about Meyers singleton: Singleton & theSingleton() { static Singleton instance; return instance; } Which in the proper context is perfectly fine. This is wrong: class myclass { // can have state // ... public static myclass m = new myclass(); // globally accessible static instance, which can have state } and the first link itself explain why.