OwnedPtr: Implement assignment operators

This commit is contained in:
apio 2023-01-13 18:54:25 +01:00
parent 9454b65682
commit 445aeed80d
Signed by: apio
GPG Key ID: B8A7D06E42258954

View File

@ -7,6 +7,11 @@ template <typename T> class SharedPtr;
template <typename T> class OwnedPtr
{
public:
OwnedPtr()
{
m_ptr = nullptr;
}
OwnedPtr(T* ptr)
{
m_ptr = ptr;
@ -25,6 +30,20 @@ template <typename T> class OwnedPtr
other.m_ptr = nullptr;
}
OwnedPtr<T>& operator=(const OwnedPtr<T>& other) = delete;
OwnedPtr<T>& operator=(OwnedPtr<T>&& 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;