| 11 | |
| 12 | |
| 13 | class CObj |
| 14 | { |
| 15 | public: |
| 16 | CObj() {refCount = 1; val = 0; next = 0;} |
| 17 | ~CObj() {if( next ) next->Release();} |
| 18 | |
| 19 | CObj &operator=(CObj &other) |
| 20 | { |
| 21 | val = other.val; |
| 22 | if( next ) |
| 23 | next->Release(); |
| 24 | next = other.next; |
| 25 | if( next ) |
| 26 | next->AddRef(); |
| 27 | return *this; |
| 28 | }; |
| 29 | |
| 30 | void AddRef() {refCount++;} |
| 31 | void Release() {if( --refCount == 0 ) delete this;} |
| 32 | |
| 33 | void SetVal(int _val) {this->val = _val;} |
| 34 | int GetVal() const {return val;} |
| 35 | |
| 36 | int &operator[](int) {return val;} |
| 37 | const int &operator[](int) const {return val;} |
| 38 | |
| 39 | int refCount; |
| 40 | |
| 41 | int val; |
| 42 | |
| 43 | CObj *next; |
| 44 | }; |
| 45 | |
| 46 | CObj *CObj_Factory() |
| 47 | { |