Changeset 282 in Sophya for trunk/SophyaLib/BaseTools
- Timestamp:
- Apr 29, 1999, 2:46:32 PM (26 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaLib/BaseTools/rcptr.h
r281 r282 6 6 // This implements a very simple "smart pointer" with reference counting. 7 7 // Many refinements are possible 8 // - implement operator =9 8 // - const propagation 10 // - invasive, when type T has field refcnt, instead of list9 // ... 11 10 12 11 // Principle : use RCPtr<T> instead of T* … … 22 21 class RCPtr { 23 22 public: 24 RCPtr(T* obj ) {23 RCPtr(T* obj=0) { 25 24 x = obj; 26 25 cnt = new int; … … 32 31 cnt = other.cnt; 33 32 (*cnt)++; 33 } 34 35 RCPtr<T>& operator = (RCPtr const& other) { 36 (*cnt)--; 37 if (!*cnt) { 38 delete x; 39 delete cnt; 40 } 41 x = other.x; 42 cnt = other.cnt; 43 (*cnt)++; 44 return *this; 34 45 } 35 46
Note:
See TracChangeset
for help on using the changeset viewer.