fluffy_muffin fluffy_muffin - 22 days ago 6
C++ Question

Should I be deleting local pointers that point to static

As the question title implies, if I have some static constant. Let's say a large number of static arrays and I need to determine which static array to use I can do so by checking some conditions and returning a pointer to the static array that is needed.

However, if I store

(type) * (name) = (static array)
in some function do I need to call
delete
on this?

Answer

If by "static array" you mean you declared static int x[100]; somewhere, and your function is returning a pointer to the first element of x (e.g. function int *foo ends with return x;, and you do int *bar = foo();), no, you definitely don't want to delete that pointer; it wasn't allocated from the heap with new, so it must not be deleted; delete only deals with heap memory.