Listing 4: Using RRef.

class Foo {
    public: 
        Foo() {}
        RRef<Bar> getBar() const {return _bar;}
        void reset() {_bar.reset();}
    private: 
        DynObj<Bar> _bar;
};
int main() {
    Foo foo; 
    RRef<const Bar> bar( foo.getBar() );
    bar().constMethod(); // ok
    foo.reset(); // destroys bar    
    bar().constMethod(); // assert fails
}