OwnedPtr: Implement assignment operators
This commit is contained in:
parent
9454b65682
commit
445aeed80d
@ -7,6 +7,11 @@ template <typename T> class SharedPtr;
|
|||||||
template <typename T> class OwnedPtr
|
template <typename T> class OwnedPtr
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
OwnedPtr()
|
||||||
|
{
|
||||||
|
m_ptr = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
OwnedPtr(T* ptr)
|
OwnedPtr(T* ptr)
|
||||||
{
|
{
|
||||||
m_ptr = ptr;
|
m_ptr = ptr;
|
||||||
@ -25,6 +30,20 @@ template <typename T> class OwnedPtr
|
|||||||
other.m_ptr = nullptr;
|
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
|
T* ptr() const
|
||||||
{
|
{
|
||||||
return m_ptr;
|
return m_ptr;
|
||||||
|
Loading…
Reference in New Issue
Block a user