Passing a value into a bound class.,
Members - Reputation: 714
Posted 30 September 2012 - 03:27 PM
I strongly suggest you read this article: http://gameprogrammi.../singleton.html Singletons have a lot of attractive features at first glance, but they're really a bad idea in the long run.
I do understand the difference between a plain global and the singleton pattern, but functionally they serve the same purpose of providing global access to the same variable anywhere in your program. Additionally, my engine is designed so I could have multiple instances of it running in the same program. Using a singleton for the engine would prevent me from doing this.
As far as malicious use goes (although I'm not sure why that would ever be a concern), your singleton example above is just as susceptible:delete Engine::get();
To each his own. Let's not go any further off topic.
protected: friend void Game::EndGame(); ~Engine();
now only Game::EndGame() can call delete on singleton. applies to "get" and any other functions too.