Default value of class

davidb ta-nospam-zz at gmx.at
Sun May 20 06:13:28 PDT 2007


Dave schrieb:
> David B. Held wrote:
>> Can anyone tell me the expected runtime behavior of this program?
>>
>> class Foo
>> { }
>>
>> void main()
>> {
>>     Foo foo;
>>     assert(foo == null);
>> }
>>
>> It's certainly not what I expected, and I want to know if I should 
>> file a bug report or not.
>>
>> Dave
> 
> Try 'assert(foo is null);'

See http://www.digitalmars.com/d/operatoroverloading.html

 > Note: Comparing a reference to a class object against null  should be 
 > done as:
 >> if (a is null)
 > and not as:
 >> if (a == null)
 > The latter is converted to:
 >> if (a.opEquals(null))

which will fail if a is null because it can't use it to reference to 
opEquals()

david



More information about the Digitalmars-d mailing list