Segfault (NullPointerException) in Linux

Qian Xu quian.xu at stud.tu-ilmenau.de
Wed Mar 18 15:44:52 PDT 2009


Frank Benoit wrote:
> Qian Xu schrieb:
> ----------- code 2 (current solution) --------------
>> public test(MyObj obj)
>> {
>>   if (obj !is null &&
>>       obj.getObj2 !is null &&
>>       obj.getObj2.getObj3 !is null)
>>   {
>>      obj.getObj2.getObj3.test();
>>   }
>> }
>>
>> ------------------------------------------------------
> 
> If you want to be able to return something like "nothing", you can use
> NullObject. That is, return an object that lets you navigate the
> references and lets you test for it being a "null" object.
> 
> auto o = obj.getObj2.getObj3;
> if( !o.isNull() ){
>     o.test();
> }

Hi, I have tried your code

But gdc said, "Error: no property 'isNull' for type 
'NullPointerExceptionTest.MyObj'

Did I miss something?


-- 
Xu, Qian (stanleyxu)
  http://stanleyxu2005.blogspot.com


More information about the Digitalmars-d-learn mailing list