// test using reference as with possible error values. #include #include class Test { public: string name; }; Test *a; Test b; Test& get(int i) { if ( i == 0 ) { return *a; } if ( i == 1 ) { return b; } // if ( i == 0 ) { //return NULL; // } } void main () { a = new Test(); a->name = "a"; b.name = "b"; Test& c = get(0); Test& d = get(1); delete a; Test* e = new Test(); e->name = "struf"; cout << "c says : " << c.name << endl; cout << "d says : " << d.name << endl; }