Array array class template

xiaoxiao2021-03-06  61

/Array.h/#ifndef AVALON_ARRAY_H # define AVALON_ARRAY_H # include #include namespace AVALON_ARRAY {const int DefaultArraySize = 12; // default length of template class Array {public: // release mechanism configured function explicit Array (int size = DefaultArraySize) {init (size, 0);} Array (const T * array, int array_size) {init (array_size, array);} Array (const Array & rhs) {init (rhs._size , rhs.ia);} Virtual ~ array (void) {delete [] a;} public: / / equal and non-equal operation BOOL OPERATOR == (const array&) Const; Bool Operator! = (const array&) Const ; // Assignment Operator Array & Operator = (Const Array &); // Subscript Operator (No Index Check Function) Virtual T & Operator [] (const INDEX) {Return IA [index]; } // Virtual void sort (); // Find the minimum, large value // Virtual t max () const; // virtual t max () const; //, in the array, find the return for the first time in the array The index of the appearance, otherwise returns the length INT size () const {return _size;} protected: // static const defaultArraysize; // Default length // Use the shared code of constructor Void Init (int SZ, const t * array); // ok // int _siz E; // Array length t * ia;}; // Template Inline void array :: init (int SZ, const t * array) {_size = SZ; IA = new T [_size] ; If (null == array) {for (int ix = 0; ix <_size; iv) // initialization array IA [ix] = T (0); return;} for (int = 0; ix < _Size; ix) IA [ix] = array [ix];}} // namespace end /

#ENDIF

转载请注明原文地址:https://www.9cbs.com/read-112053.html

New Post(0)