/** * @file main.cpp * @brief Example usage of the Array class */ #include #include /** * @class Array * @brief A dynamic array class with resize and index bounds checking */ template class Array { private: T *mem; /**< Pointer to the memory block */ int size; /**< Current size of the array */ public: /** * @brief Constructor * @param size Initial size of the array */ Array(int size){ this->size = size; mem = new T[size]; } /** * @brief Resize the array * @param newSize New size of the array */ void resize(int newSize){ T *newMem = new T[newSize]; for (int i=0;i=size){ resize(index+1000); } return mem[index]; } }; /** * @brief Main function * @param argc Number of command-line arguments * @param argv Command-line argument values * @return 0 on success */ int main(int argc, char *argv[]){ Array myArray(40); myArray[56] = 1.23456; printf("array[56] = %f\n",myArray[56]); return 0; }