Default value of class
David B. Held
dheld at codelogicconsulting.com
Sun May 20 09:35:43 PDT 2007
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
More information about the Digitalmars-d
mailing list