I have a pointer to a class, that have a pointer to a multidimensional array but I can't seem to delete it from memory when I need to or set it to NULL.
#define X 10
#define Y 10
struct TestClass
{
public:
int *pArray[X][Y];
};
// different tries, none working:
delete Pointer_To_TestClass->pArray[0][0];
delete[] Pointer_To_TestClass->pArray[0][0]
// or by simply:
Pointer_To_TestClass->pArray[0][0] = NULL;
I know the array has data because I can see the results on screen. Also check if it's NULL already, then doesn't try to delete it.
Since I want to delete a pointer in another pointer - is this a special circumstance that works differently? Like it deletes the first pointer holding the other pointer instead of the pointer inside the pointer (pArray is the second pointer, Pointer_To_Testclass is the first pointer)
UPDATE/EXPLANATION
I want to be able to delete pArray[0][0] while pArray[0][1] still exists and if [0][0] doesn't exist it should be equal to NULL. Most because I want to access this array by [X][Y] values for easy access. If [0][0] is a pointer, it should be NULL when deleted so I can check if it is NULL.
Anyone has any ideas?
int *pArray[1][2];
yieldsdeclare pArray as array 1 of array 2 of pointer to int
on cdecl. – Yoginistd::vector
for arrays in C++. A pointer to a jagged 2D array would then be declared asstd::vector<std::vector<int> >*
. – SimasimahObject
, where each has an x and y inside it? Useerase
to erase one object from the vector. – Yoginistd::vector
(which can change its size), add the objects in when you need to usingpush_back
, and remove the objects when you need to usingerase
. – YoginiPointer_To_TestClass
declared? Is it aTestClass
object, or a pointer to aTestClass
object? That might be messing up your syntax inPointer_To_TestClass->
– Acrimony