Question: IN C++ Create a class to act as a generic array (i.e. the user will be able to choose the data type to be stored
IN C++ Create a class to act as a generic array (i.e. the user will be able to choose the data type to be stored by passing the appropriate template argument. Integer template arguments will also be used to set the upper and lower bounds of the array. Provide all necessary functionality to allow the class to act as an array ([] operator, = operator etc.). The array does not need to provide input or output methods to act on the entire array. Errors within operators and constructors will be handled with exceptions (try, throw, catch) Demonstrate that your array operators work inside a function if the array is passed in by reference as a const. Provide a Copy method to provide the same functionality as the = operator. Also, provide GetAt and SetAt methods to provide ways of getting and setting values at a particular index in the array.
what i have so far:
Array.h
#ifndef ARRAY_H #define ARRAY_H
template
template
template
template
template
for (i = 0; i < lower, upper; i++) Data[i] = A.Data[i]; }
template
template
for (i = 0; i < upper; i++) Data[i] = A.Data[i]; return *this; }
template
for (i = 0; i < upper; i++) Data[i] = A.Data[i]; return *this; }
template
template
#endif
><><><><><><>><><<><><><><><><<><><><<><><><>
main.cpp
#include
using namespace std;
#include "Array.h"
void Func(const Array
void main() { try { Array
pTemp = new char[10]; A1[3] = 99; Func(A1); delete[] pTemp; // if a throw occurs with the [] operator, this delete will not be done (memory leak) } catch (Array
void Func(const Array
pretty sure my header file is right but when i go to test in main all i get is the error messages im throwing. how do i make it work and how do i display that everything is working and all the conditions are tested and correct?
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
