Gaijinco wrote:
If I do something like:
int* Foo(){
int *aux, *p, *q;
/*
NIFTY CODE HERE
Supposedly, filling 'aux' with a valid pointer value...
*/
return aux;
}
Does the program destroy the pointers after exiting the function or
should I delete them anyway at the end of the function?
Returning a value of a pointer is orthogonal to any other action, if by
the time you return the value (and after the function exits) the value is
still valid.
The program destroys _every_ object with automatic storage duration upon
leaving the scope in which they are defined. So, yes, the pointers are
destroyed. Destroying a pointer, though, does NOT mean deleting the
object to which that pointer points. The decision whether to delete or
not to delete something is also completely orthogonal to the rest of the
stuff here. If you don't need the object any more, delete it (through
a pointer to it). If you need the object to survive longer, don't delete
it.
V