What's wrong with this code?

Michal Minich michal.minich at gmail.com
Sat Jan 8 12:46:01 PST 2011


On Sat, 08 Jan 2011 20:34:39 +0000, Sean Eskapp wrote:

> 		if(left == null)

1) write if (left is null) instead if checking for null. Equality 
operator is rewritten to a.opEquals(b), which you don't want if you 
checking for null.

> this()
> {
>     left = right = null;
> }
2) default constructor as you written it is not needed, fields are always 
initialized to default value of their type, which is in this case null.

> private const Fib* left, right;
3) Classes in D are reference types. It should be 
 private const Fib left, right;

4) second constructor - Classes in D are reference types, & operator is 
not needed (see point 3), parameter left and right are already references 
to class.


More information about the Digitalmars-d-learn mailing list