• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Automagic instantiation of singletons? (Christian Brunschen)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Automagic instantiation of singletons? (Christian Brunschen)


  • Subject: Re: Automagic instantiation of singletons? (Christian Brunschen)
  • From: Theo Vosse <email@hidden>
  • Date: Fri, 18 Nov 2005 18:00:42 +0100

The common way in C++ for instantiating singletons is

class Singleton
{
public:
	Singleton()
	{
		// Instantiation code here
	}
};
static Singleton my_singleton_instantiation_dont_touch;

The static variable will cause Singleton::Singleton() to be called before main() is executed. You can mix C++ and Objective-C code without problems. There are (AFAIK) only problems with this trick when loading dynamic libraries in a multi-threaded context.

A more Cocoa-like way of doing it might be to use +initialize.
_______________________________________________
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


  • Follow-Ups:
    • Re: Automagic instantiation of singletons? (Christian Brunschen)
      • From: Scott Ribe <email@hidden>
  • Prev by Date: Picking up Fragment Specifier
  • Next by Date: RE: Asynchronous Methods Question
  • Previous by thread: Re: Automagic instantiation of singletons? (Christian Brunschen)
  • Next by thread: Re: Automagic instantiation of singletons? (Christian Brunschen)
  • Index(es):
    • Date
    • Thread