#ifndef DYNAMIC_2D_ARRAY_H_HEADER_GUARD_ #define DYNAMIC_2D_ARRAY_H_HEADER_GUARD_ // dynamic_2d_array class by David Maisonave (609-345-1007) (www.axter.com) // Description: // The dynamic array class listed below is more efficient then other // similar classes that use temporary objects as return types, or use // an std::vector as a return type. // // It's also more compatible with a C style 2D array, in that the // array is in one continuous memory block. This makes it possible // to pass this array object to a C Function that has a C-Style // 2D array for a parameter. // Example usage: /* dynamic_2d_array MyIntArray(12, 34); MyIntArray[0][1] = 123; cout << MyIntArray[0][1] << endl; */ template < class T> class dynamic_2d_array { public: dynamic_2d_array(size_t row, size_t col):m_row(row),m_col(col), m_data((row!=0&&col!=0)?new T[row*col]:NULL){} dynamic_2d_array(const dynamic_2d_array&src):m_row(src.m_row),m_col(src.m_col), m_data((src.m_row!=0&&src.m_col!=0)?new T[src.m_row*src.m_col]:NULL){ for(size_t r=0;r