TITLE: Detecting null references PROBLEM: euamts@eua.ericsson.se (Mats Henricson), 1 Jun 92 What is the standard way to indicate failure with a function which returns a reference. In my C programs, when I want to indicate failure I just returned NULL. But I am currently working on a table object which I would like to return a refernce when sent the message lookup(key), (is this a good place to use pointers? I'm trying to get away from the habit of writing C code in my C++ programs) I have no exceptions or anything, I'm using Borland C++ v2.0 PROBLEM: weikart@prl.dec.com (Chris Weikart), 1 Jun 92 DEC Paris Research Lab (PRL) I recommend this approach. Furthermore, to avoid name-space pollution, I recommend that these kinds of `null' objects be defined as static class members. For example: header: class aString { ... static const aString Null; static const char null; ... }; source: const aString aString::Null ((char *)NULL); const char aString::null = '\0'; client: aString foo; ... if (foo == aString::Null || foo[0] == aString::null) // whatever [ Our convention is to pass arguments as pointers. Perhaps this might be an acceptable alternative. -adc ]