Re: Automagic instantiation of singletons? (Christian Brunschen)
Re: Automagic instantiation of singletons? (Christian Brunschen)
- Subject: Re: Automagic instantiation of singletons? (Christian Brunschen)
- From: Theo Vosse <email@hidden>
- Date: Sun, 20 Nov 2005 13:07:13 +0100
That's a lousy way to do it in C++, because you have no portable and
reliable way to control the order of instantiation, so you have to
make
*sure* that there is *no* dependency anywhere between any 2
singletons,
It is a simple way of making things like factory singletons. If you
have more complex needs, you should write initialization code, of
course.
It's even worse in Objective-C++, since the C++ statics may be
constructed
before the Cocoa runtime is completely up, and may be destructed
after it is
at least partially torn down.
The C++ standard is quite clear on what should happen (the
constructors are called before main), and although I don't know of a
guarantee that any interaction with NS classes will function at that
point, it should if the descriptions of +(void)initialize are
correct. However, I do consider it a bad idea to use C++ singletons
to set up something in Cocoa.
Theo
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden