Implement a class genVector that generalizes the vector class to create a safe array with general starting and ending indices. For instance,
genVector<int> vA(1,10), vB(-1,8);
creates objects vA and vB
with index ranges 1 <= i <=10 and -1 <i < 8 , respectively. Objects of type genVector can be indexed within their defined range. For instance,
for (i=-1; i<=8; i++) // initalize all vector elements to 0
Derive genVector from the vector class by using public inheritance. Override the index operator so it accepts indices in the correct range. Implement a derived member function resize() that resizes the vector and resets the beginning and ending indices. These actions prevent references to the vector index operator and resize() function unless the programmer uses the scope operator "::".
template <typename T>
class genVector: public vector<T>
genVector(int low, int high);
// vector has high - low+1 elements in range [low,high]
T& operator  (int i);
// operator verifies that lower <= i <= upper.
// if not, it throws the indexRangeError exception
void resize(int lowIndex, int highIndex);
// resize vector and set range to [lowIndex, highIndex]
Place genVector in header file "genvec.h" and write a program that declares the following objects:
Initialize ucLetter so that ucLetter='A',...,ucLetter='Z'. Initialize tempVector so that tempVector is the Fahrenheit equivalent of Celsiius tempature t. Recall that
Display the contents of each vector.
Based on these requirements, here's what I have so far.
The genvec.h header file:
template <typename T>
class genVector:public vector<T>
genVector(int low, int high)
T& operator (int i)
if ((i < lower) || (i > upper))
"genVector: index range error",i,size());
return vector<T>::operator  (i);
void resize(int lowIndex, int highIndex)
And the file I am using to test my class:
using namespace std;
genVector<double> tempVector (-10,25);
When I compile the code, it does not provide any errors from the compiler. I get an error once it's compiled indicating that the problem has encountered a problem and needs to close. I've found in the past that usually means that I have a memory leak or something of that nature. I am not sure where the problem lies in this specific code, however.
Any assistance that anyone could provide would be greatly appreciated.