From 4fa33a9689e4d77a9ad3e283ec789f54f9971954 Mon Sep 17 00:00:00 2001 From: apio Date: Fri, 23 Dec 2022 10:31:48 +0100 Subject: [PATCH] SharedPtr: Add operator= --- luna/include/luna/SharedPtr.h | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/luna/include/luna/SharedPtr.h b/luna/include/luna/SharedPtr.h index 08c09931..4cf1bcff 100644 --- a/luna/include/luna/SharedPtr.h +++ b/luna/include/luna/SharedPtr.h @@ -1,7 +1,6 @@ #pragma once #include #include -#include #include #include @@ -54,6 +53,24 @@ template class SharedPtr } } + SharedPtr& operator=(const SharedPtr& other) + { + if (&other == this) return *this; + + if (m_ref_count && m_ref_count->unref()) + { + delete m_ref_count; + delete m_ptr; + } + + m_ptr = other.m_ptr; + m_ref_count = other.m_ref_count; + + m_ref_count->ref(); + + return *this; + } + T* ptr() const { return m_ptr;