1 /******************************************************************************* 2 / 3 / File: array_delete.h 4 / 5 / Description: Template for deleting a new[] array of something. 6 / 7 / Copyright 1998-1999, Be Incorporated, All Rights Reserved 8 / 9 *******************************************************************************/ 10 11 12 #if !defined( _array_delete_h ) 13 #define _array_delete_h 14 15 // Oooh! It's a template! 16 template<class C> class array_delete { 17 C * & m_ptr; 18 public: 19 // auto_ptr<> uses delete, not delete[], so we have to write our own. 20 // I like hanging on to a reference, because if we manually delete the 21 // array and set the pointer to NULL (or otherwise change the pointer) 22 // it will still work. Others like the more elaborate implementation 23 // of auto_ptr<>. Your Mileage May Vary. 24 array_delete(C * & ptr) : m_ptr(ptr) {} 25 ~array_delete() { delete[] m_ptr; } 26 }; 27 28 29 #endif /* array_delete_h */ 30 31