diff --git a/BAN/include/BAN/RefPtr.h b/BAN/include/BAN/RefPtr.h index e717485d..9d9364a9 100644 --- a/BAN/include/BAN/RefPtr.h +++ b/BAN/include/BAN/RefPtr.h @@ -53,7 +53,6 @@ namespace BAN if (m_pointer) m_pointer->ref(); } - ~RefPtr() { clear(); } template @@ -75,6 +74,10 @@ namespace BAN RefPtr(const RefPtr& other) { *this = other; } RefPtr(RefPtr&& other) { *this = move(other); } + template + RefPtr(const RefPtr& other) { *this = other; } + template + RefPtr(RefPtr&& other) { *this = move(other); } RefPtr& operator=(const RefPtr& other) { @@ -93,6 +96,25 @@ namespace BAN return *this; } + template + RefPtr& operator=(const RefPtr& other) + { + clear(); + m_pointer = other.m_pointer; + if (m_pointer) + m_pointer->ref(); + return *this; + } + + template + RefPtr& operator=(RefPtr&& other) + { + clear(); + m_pointer = other.m_pointer; + other.m_pointer = nullptr; + return *this; + } + T* ptr() { ASSERT(!empty()); return m_pointer; } const T* ptr() const { ASSERT(!empty()); return m_pointer; } @@ -114,6 +136,9 @@ namespace BAN private: T* m_pointer = nullptr; + + template + friend class RefPtr; }; }