Main Page | Namespace List | Class Hierarchy | Compound List | File List | Namespace Members | Compound Members | File Members | Related Pages

NoPtr::RRefable Class Reference

#include <RRefable.hh>

List of all members.

Detailed Description

Derive from this class to make your subclass a RRef'able object.

You can then give an instance of your class (or subclass thereof) to an RRef. When the Foo goes out of scope and gets destroyed, any RRefs referencing that Foo will know that it no longer exists and an assertion will fail if you attempt to access that Foo through the RRef.

RRefable has no public methods. It simply adds some functionality to the destructor of your base classes, so that the RRefs can be notified. This functionality is active only in debug mode (see next note).

In a release build (i.e. when -DNDEBUG is given to compiler), RRefable is completely empty so there is no cost for a release build, but you get reference checking in debug mode.

RRefable does not include any data and so does not need a virtual destructor. Since RRefable has no public interface, it wouldn't make much sense to use it polymorphically anyways.

    class Foo: public RRefable 
            virtual void method() {...}
    class DFoo: public Foo {...};
    int main()
        RRef<Foo> foo;
        Foo* aFoo = new DFoo;
        foo = *aFoo; // create RRef to aFoo
        assert(foo.isNotNull()); // succeeds
        delete aFoo;
        assert(foo.isNull()); // succeeds
        foo().method(); // causes assertion to fail

Add tests for the copy/assign to make sure works
Oliver Schoenborn
Apr 2003

Definition at line 29 of file RRefable.hh.

Protected Member Functions

 RRefable (const RRefable &)
 A copy has its own ref usage, so nothing to do (but default one by compiler would be wrong).

void operator= (const RRefable &rhs)
 A copy has its own ref usage, so nothing to do (but default one by compiler would be wrong).

The documentation for this class was generated from the following file:
Generated on Mon Aug 4 18:51:33 2003 for NoPtr C++ Library by doxygen 1.3.2