Segfault (NullPointerException) in Linux
Frank Benoit
keinfarbton at googlemail.com
Wed Mar 18 10:19:40 PDT 2009
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();
}
More information about the Digitalmars-d-learn
mailing list