Data Structures, Algorithms, & Applications in C++
Chapter 5, Exercise 7
The code is given below and in the file
arrayListWithOverloadIndex.h. Test code is
included in arrayListWithOverloadIndex.cpp.
template<class T>
class arrayListWithOverloadIndex : public arrayList<T>
{
public:
// constructor and destructor
arrayListWithOverloadIndex(int initialCapacity = 10)
: arrayList<T> (initialCapacity) {}
T& operator[](int);
};
template<class T>
T& arrayListWithOverloadIndex<T>::operator[](int theIndex)
{// Return a reference to position theIndex of the list.
checkIndex(theIndex);
return element[theIndex];
}