I've seen numerous functions like:
The check for p is so that you don't delete it twice (which would cause a problem). But if an array gets passed to it, you've got a problem.Code:template <typename T> void SafeDelete(T *&p) { if ( p ) { delete p; p = NULL; } }
Is there a way to do something *like* this:
Code:template <typename T> void SafeDelete(T *&p) { if ( p ) { if ( isArray( p ) ) delete [] p; else delete p; p = NULL; } }