#include <reference_counted.h>
Public Member Functions | |
ReferenceCounted () | |
Initialize the reference count to zero. | |
virtual | ~ReferenceCounted () |
A constructor that does nothing. | |
void | inc_ref () |
Increase the reference by one. | |
void | dec_ref () |
Decrease the reference by one. Deallocate the object from the heap if the reference count is zero. | |
int | get_ref_count () |
Return the number of references to the object. | |
Private Attributes | |
int | ref_count_ |
The number of references to the object. |
It is strongly advised that reference-counted objects only be created on the heap. If they are created on the stack, you should not call dec_ref
; otherwise the program will crash.
ReferenceCounted::ReferenceCounted | ( | ) | [inline] |
Initialize the reference count to zero.
virtual ReferenceCounted::~ReferenceCounted | ( | ) | [inline, virtual] |
A constructor that does nothing.
void ReferenceCounted::dec_ref | ( | ) | [inline] |
Decrease the reference by one. Deallocate the object from the heap if the reference count is zero.
This function should not be called if the object is created on the stack.
int ReferenceCounted::get_ref_count | ( | ) | [inline] |
Return the number of references to the object.
void ReferenceCounted::inc_ref | ( | ) | [inline] |
Increase the reference by one.
int ReferenceCounted::ref_count_ [private] |
The number of references to the object.