
9 Jan
2005
9 Jan
'05
8:34 p.m.
Thomas Beckmann wrote:
Wouldn't it be easier to change AddDependency to something like the following:
static void AddDependency ( ) { static bool first = true;
if ( first ) { s_inst = static_cast < T * > ( A :: Create ( ) ); dependents = 0; first = false; } ++dependents; }
The problem is that this makes recreating the singleton impossible... you lose the phoenix effect. Also, creating the singleton might inadvertently result in creating something else that creates something else that has a singleton dependency. If such a thing happens, dependents should be in a correct state ( aka incremented ) before create is called. -Jason