Advertisement
Guest User

Untitled

a guest
Dec 5th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.40 KB | None | 0 0
  1. SmartPointer() : ptr(nullptr), counter(nullptr) {}
  2.     SmartPointer(T* ptr) : ptr(ptr), counter(new ReferenceCounter(1)) {}
  3.     SmartPointer(const SmartPointer<T>& other) : ptr(other.ptr), counter(other.counter)
  4.     {
  5.         if (counter)
  6.             counter->AddRef();
  7.     }
  8.     ~SmartPointer()
  9.     {
  10.         if (counter)
  11.         {
  12.             counter->DelRef();
  13.             if (counter->Count() == 0)
  14.             {
  15.                 delete counter;
  16.                 delete ptr;
  17.             }
  18.         }
  19.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement