How to write a singleton template?

Jarrett Billingsley kb3ctd2 at yahoo.com
Tue Mar 14 19:11:17 PST 2006


"Li Jie" <cpunion at gmail.com> wrote in message 
news:dv7s7e$1hee$1 at digitaldaemon.com...

Versions A and B work fine, but version C doesn't work because of this line:

> if (_instance == null)

Change it to

if(_instance is null)

This is because the == operator calls opEquals on the first object, so 
_instance == null is the same as _instance.opEquals(null) - which is 
obviously going to cause a segfault if _instance is null.  Use the "is" (and 
the "!is") operator to determine what a class reference is pointing to (like 
null). 





More information about the Digitalmars-d mailing list