How to write a singleton template?

Li Jie cpunion at gmail.com
Tue Mar 14 23:55:30 PST 2006


In article <dv80jr$1m1g$1 at digitaldaemon.com>, Jarrett Billingsley says...
>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). 

Thannnks.

It works find.
But, Versions A and B work can't work on my computer. 
Segment fault at the same line, and I don't know why.

My system:
P4 3.0G, 1G RAM, Gentoo 2006.0
gcc 3.4.4, dmd 0.149


Thanks again.

- Li Jie





More information about the Digitalmars-d mailing list