www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Re: Pointers vs. References

Bill Baxter Wrote:
 Anyway, yeh, I'd be happy with a warning (or an error really -- unless 
 someone can think of a case where you really _want_ to crash your 
 program like that).

Here's one: say you have a clas Wrapper that wraps another class. You might want to overload opEquals() to test against the wrapped object reference, so opEquals(null) will return true if the wrapped object is null. For erxample, Wrapper w = new Wrapper(null); // ... if(w == null) // Doesn't segfault and does what you want it to This could be throught of as a bad design decision (of course, I think all operator overloading in general makes code harder to read, with the possible exception of Box/Variant a very few other uses), but it's a valid use case.
Jun 14 2007