From e9321fc4dc678cdf0bf63960f63e401a3b730067 Mon Sep 17 00:00:00 2001 From: Shon Ferguson <shonferg@users.sourceforge.net> Date: Tue, 30 May 2006 03:03:13 +0000 Subject: [PATCH] Added default constructor to Ref which initializes pointer to NULL. Added destructor which decrements reference count on any referenced object. --- obj/Ref.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/obj/Ref.h b/obj/Ref.h index 1a2db489..35e16fad 100644 --- a/obj/Ref.h +++ b/obj/Ref.h @@ -9,8 +9,10 @@ All rights reserved. Please see niflib.h for licence. */ */ template <class T> class Ref { public: + Ref(); Ref( T * object = NULL ); Ref(const Ref & ref_to_copy ); + ~Ref(); operator T*() const; T& operator*() const; @@ -31,6 +33,9 @@ protected: T* _object; }; +template <class T> +Ref<T>::Ref() : _object(NULL) {} + template <class T> Ref<T>::Ref( T * object ) : _object(object) {} @@ -43,6 +48,14 @@ Ref<T>::Ref(const Ref & ref_to_copy ) { } } +template <class T> +Ref<T>::~Ref() { + //if object insn't null, decrement reference count + if ( _object != NULL ) { + _object->SubtractRef(); + } +} + template <class T> Ref<T>::operator T*() const { return _object; -- GitLab