template<class ObjectType, class ReferenceCountingType = ReferenceCountedObject>
class WeakReference< ObjectType, ReferenceCountingType >
This class acts as a pointer which will automatically become null if the object to which it points is deleted.
To accomplish this, the source object needs to cooperate by performing a couple of simple tasks. It must embed a WeakReference::Master object, which stores a shared pointer object, and must clear this master pointer in its destructor.
E.g.
class MyObject
{
public:
MyObject()
{
}
~MyObject()
{
masterReference.clear();
}
private:
};
MyObject* n = new MyObject();
MyObject* pointer1 = myObjectRef;
delete n;
MyObject* pointer2 = myObjectRef;
- See also
- WeakReference::Master
template<class ObjectType, class ReferenceCountingType = ReferenceCountedObject>
bool WeakReference< ObjectType, ReferenceCountingType >::wasObjectDeleted |
( |
| ) |
const |
|
inlinenoexcept |
This returns true if this reference has been pointing at an object, but that object has since been deleted.
If this reference was only ever pointing at a null pointer, this will return false. Using operator=() to make this refer to a different object will reset this flag to match the status of the reference from which you're copying.