From 445aeed80d3c00e6f79f2dc8364e51fc4954898f Mon Sep 17 00:00:00 2001 From: apio Date: Fri, 13 Jan 2023 18:54:25 +0100 Subject: [PATCH] OwnedPtr: Implement assignment operators --- luna/include/luna/OwnedPtr.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/luna/include/luna/OwnedPtr.h b/luna/include/luna/OwnedPtr.h index 01911ea8..319b8160 100644 --- a/luna/include/luna/OwnedPtr.h +++ b/luna/include/luna/OwnedPtr.h @@ -7,6 +7,11 @@ template class SharedPtr; template class OwnedPtr { public: + OwnedPtr() + { + m_ptr = nullptr; + } + OwnedPtr(T* ptr) { m_ptr = ptr; @@ -25,6 +30,20 @@ template class OwnedPtr other.m_ptr = nullptr; } + OwnedPtr& operator=(const OwnedPtr& other) = delete; + + OwnedPtr& operator=(OwnedPtr&& other) + { + if (&other == this) return *this; + + if (m_ptr) delete m_ptr; + + m_ptr = other.m_ptr; + other.m_ptr = nullptr; + + return *this; + } + T* ptr() const { return m_ptr;