Forgetting to delete leads to memoryleaks

This commit is contained in:
Dynamitos
2023-11-07 16:55:13 +01:00
parent 46a0befb80
commit ecb5050dc7
29 changed files with 178 additions and 173 deletions
+13 -2
View File
@@ -145,6 +145,7 @@ public:
OwningPtr(OwningPtr<F>&& other)
{
pointer = dynamic_cast<T*>(*other);
other.clear();
}
OwningPtr(const OwningPtr& other) = delete;
OwningPtr(OwningPtr&& other) noexcept
@@ -162,9 +163,14 @@ public:
Deleter()(pointer);
}
pointer = other.pointer;
other.pointer = nullptr;
}
return *this;
}
~OwningPtr()
{
Deleter()(pointer);
}
operator RefPtr<T>()
{
return RefPtr<T>(pointer);
@@ -189,14 +195,19 @@ public:
{
return pointer;
}
constexpr bool operator==(const OwningPtr& rhs) const noexcept
constexpr bool operator==(std::nullptr_t) const noexcept
{
return pointer == rhs.pointer;
return pointer == nullptr;
}
constexpr auto operator<=>(const OwningPtr& rhs) const noexcept
{
return pointer <=> rhs.pointer;
}
// INTERNAL USE
constexpr void clear()
{
pointer = nullptr;
}
private:
friend class RefPtr<T>;
T* pointer;