Use delete[] for array types in MxPtrList::Destroy

This commit is contained in:
Christian Semmler 2025-05-18 10:41:50 -07:00
parent b90215603b
commit c695834d66
2 changed files with 12 additions and 2 deletions

View File

@ -8,7 +8,7 @@ include(CheckCXXSourceCompiles)
include(CMakeDependentOption)
include(CMakePushCheckState)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

View File

@ -5,6 +5,8 @@
#include "mxcore.h"
#include "mxtypes.h"
#include <type_traits>
template <class T>
class MxList;
template <class T>
@ -71,7 +73,15 @@ class MxPtrList : public MxList<T*> {
public:
MxPtrList(MxBool p_ownership) { SetOwnership(p_ownership); }
static void Destroy(T* p_obj) { delete p_obj; }
static void Destroy(T* p_obj)
{
if constexpr (std::is_pointer<T>::value) {
delete[] p_obj;
}
else {
delete p_obj;
}
}
void SetOwnership(MxBool p_ownership)
{