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

Anything and everything that's related to OGRE or the wider graphics field that doesn't fit into the other forums.
Post Reply
NoeMurr
Gnoblar
Posts: 6
Joined: Sat May 18, 2019 1:02 pm

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

Post by NoeMurr » Fri Jun 14, 2019 5:24 pm

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.
0 x

paroj
OGRE Team Member
OGRE Team Member
Posts: 854
Joined: Sun Mar 30, 2014 2:51 pm
x 170
Contact:

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

Post by paroj » Sat Jun 15, 2019 12:07 am

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.
0 x

Post Reply