ReferenceCounting.h 330 B

123456789101112131415161718192021222324252627
  1. #pragma once
  2. template< class T >
  3. class ReferenceCounting : public T
  4. {
  5. private:
  6. int ref;
  7. public:
  8. ReferenceCounting()
  9. : T()
  10. {
  11. ref = 1;
  12. }
  13. T *getThis()
  14. {
  15. ref++;
  16. return this;
  17. }
  18. T *release()
  19. {
  20. if( !--ref )
  21. delete this;
  22. return 0;
  23. }
  24. };