[OT] Re: Default value of class

Chris Nicholson-Sauls ibisbasenji at gmail.com
Sun May 20 10:19:41 PDT 2007


David B. Held wrote:
> davidb wrote:
>> 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()
> 
> Aha...thanks guys.  However, I am disturbed by two things: 1) that this 
> looks more like VB than C++ ;), and 2) that everyone in this thread is 
> named "David".  Hmm...
> 
> Dave

o_O  It only makes sense though, for a language named "D".

We have our army of Davids, and the (Ch|K)ris's... at least there's just one Walter. 
Could you imagine...

-- Chris (!) Nicholson-Sauls



More information about the Digitalmars-d mailing list