Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- template<class type>
- class counter{
- type** myptr;
- unsigned int *count;
- void countpp(){
- (*count) ++;
- }
- void countss(){
- (*count)--;
- if( (*count) == 0 ){
- delete count;
- delete *myptr;
- delete myptr;
- }
- }
- public:
- counter(type *t){
- myptr = new type*;
- count = new unsigned int;
- *myptr = t;
- (*count) = 1;
- }
- counter( const counter<type> &t ){
- myptr = t.myptr;
- count = t.count;
- countpp();
- }
- ~counter(){
- countss();
- }
- type*& get(){
- return *myptr;
- }
- type*& operator->(){
- return *myptr;
- }
- type& operator*(){
- return **myptr;
- }
- type& operator[](int idx){
- return (*myptr)[idx];
- }
- counter<type>& operator=(counter<type> & t){
- countss();
- myptr = t.myptr;
- count = t.count;
- countpp();
- return *this;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement