digitalmars.D - Class Default Value
- Alberto Simon (6/6) Apr 24 2006 I have a question... When I declare a class object no matter what the de...
- Jarrett Billingsley (3/10) Apr 24 2006 Use "is", not "==".
- Derek Parnell (21/28) Apr 25 2006 When one codes ...
I have a question... When I declare a class object no matter what the definition is and set it to null I get an runtime exception whenever I try to compare that object to null... Is that correct behavior?? and if that is correct, how do I check for an uninitialized class in a fast and efficient manner? Regards, Alberto Simon
Apr 24 2006
"Alberto Simon" <Alberto_member pathlink.com> wrote in message news:e2k4f5$1efa$1 digitaldaemon.com...I have a question... When I declare a class object no matter what the definition is and set it to null I get an runtime exception whenever I try to compare that object to null... Is that correct behavior?? and if that is correct, how do I check for an uninitialized class in a fast and efficient manner?Use "is", not "==".
Apr 24 2006
On Tue, 25 Apr 2006 13:19:02 +1000, Alberto Simon <Alberto_member pathlink.com> wrote:I have a question... When I declare a class object no matter what the definition is and set it to null I get an runtime exception whenever I try to compare that object to null... Is that correct behavior?? and if that is correct, how do I check for an uninitialized class in a fast and efficient manner?When one codes ... class Foo {}; Foo foo = new Foo; ... if (foo == null) the compile converts this to call the implied class member function 'opEquals' so this code is equivalent to if (foo.opEquals(null)) and for that to work, 'foo' must be a valid class instance. The way to check for an uninitialized class in D is to let the compiler know that's what you are trying to do, and the syntax for that is ... if (foo is null) To test if it is initialized use if(foo !is null) or if (! (foo is null) ) -- Derek Parnell Melbourne, Australia
Apr 25 2006