Page 1 of 1

Why Ogre::Singleton<T> throws runtime error instead of compile time one

Posted: Fri Jun 14, 2019 5:24 pm
by NoeMurr
Hi all,

I would like to know why the Ogre::Singleton<T> class is written in a way that it throws a runtime error instead of use the standard singleton design pattern?

I'm trying to write a tutorial about the Terrain and I need to understand why the Ogre::TerrainGlobalOptions class is written in this way to explain it correctly.

Re: Why Ogre::Singleton<T> throws runtime error instead of compile time one

Posted: Sat Jun 15, 2019 12:07 am
by paroj
the Ogre::Singleton pattern slightly derives from the textbook to allow the user to explicitly create the singleton object instead of implicitly creating it on the first getSingleton call.
E.g. declaring a singleton instance in main() makes it follow RAII.

However, this way the constructor cannot be private any more, and we have to assert on runtime that only one instance ever exists.