Misunderstanding, silly error, or compiler bug?

Peter C. Chapin pchapin at sover.net
Fri Aug 10 06:42:50 PDT 2007


Daniel919 wrote:

> Hi, welcome to D ;)

Thanks!

> Line 45 in tree.d:
> while( current != null ) {
> 
> If you use the == operator on objects, the opEqual method
> of the class will be called.

Interesting. Okay, so I'm trying to compare the Node referenced by
currrent to null. I didn't define an opEqual for class Node so does that
mean the compiler gives me a default one? I guess I would have expected
some sort of type mismatch error ('null' isn't a Node, after all).

> Now if your object was not instantiated, this will fail of course.
> 
> Instead of this, you have to check whether the reference is null:
> while( current !is null ) {

Yep. That works. Thanks (to both of you who replied).

> Another hint:
> Tree!(int) my_tree = new Tree!(int);
> don't know whether you know it, but you could use:
> auto my_tree = new Tree!(int);
> 
> D supports type inference by using the keyword auto.

Cool.

Peter


More information about the Digitalmars-d-learn mailing list