I have to create a function that can take in an array of pointers with a known size, and set all the pointers to NULL. The caveat is that I don’t know the type beforehand. This is what I have tried so far:
template <typename T>
static void Nullify(T** _Array, int _Size, unsigned int _SizeOf)
{
for (int i = 0; i < _Size; i++)
{
_Array[i * _SizeOf] = NULL;
}
}
Which is giving me errors (not the function itself, but I am trampling on memory I should not be trampling on resulting in a memory error later on). I am passing in the array (_Array – already initialized to _Size), its size (_Size), and the sizeof(Pointer*) as _SizeOf.
Any help would be greatly appreciated 🙂
You don’t need _SizeOf. This is what you want:
The compiler knows the size of a pointer, and does the math for you during the array dereference.