Go to the previous, next section.
#include <CNCL/Ptr.h>
CN_PTR
CNObject
None
CNRef, CNRefObj, CNRefNamed
This class provides an intelligent pointer to CNRefObjs, i.e. if
you copy one CNPtr to another one, then the reference count of
the CNRefObj contained in the source CNPtr is increased
automatically and the reference count of the CNRefObj contained
in the destination CNPtr is decreased automatically. See example
below.
Constructors:
CNPtr();
CNPtr(CNParam *param);
CNPtr(CNRefObj *o);
CNPtr(const CNPtr &p);
In addition to the member functions required by CNCL, CNPtr
provides:
CNPtr& operator =(const CNPtr& p)
CNRefObj data member, the reference count of the CNRefObj
data member contained in the source CNPtr is increased
automatically and the reference count of the CNRefObj data member
contained in the destination CNPtr is decreased automatically.
CNRefObj *operator ->() const
CNRefObj *get_object() const
CNRefObj data member.
Example:
CNRefObj *source_obj, *dest_obj; CNPtr *source, *dest; source_obj = new CNRefObj; source_obj->ref(); source = new CNPtr(source_obj); dest_obj = new CNRefObj; dest_obj->ref(); dest = new CNPtr(dest_obj); // ref counts // source_obj : 1 // dest_obj : 1 // copy contents of source to dest // implicitly increase counter of source_obj // implicitly decrease counter of dest_obj and delete it *dest = *source; // ref counts // source_obj : 2 // dest_obj : 0 (deleted) // implicitly decrease counter of source_obj delete source; // implicitly decrease counter of source_obj and delete it delete dest;
Go to the previous, next section.