#include
#include
using namespace std;
const int SIZE = 10;
template class MyClass {
T a[SIZE];
public:
MyClass(void)
{
int i;
for(i=0; i a[i] = i;
}
T &operator[](int i);
};
template T &MyClass::operator[](int i)
{
if(i<0 || i> SIZE-1)
{
cout << endl << "Index value of ";
cout << i << " is out of bounds." << endl;
}
return a[i];
}
int main(void)
{
MyClass int_array;
MyClass double_array;
int i;
cout << "Integer array: ";
for(i=0; i int_array[i] = i;
for(i=0; i cout << int_array[i] << " ";
cout << endl;
cout << "Double array: ";
cout.precision(2);
for(i=0; i double_array[i] = (double)i/3;
for(i=0; i cout << double_array[i] << " ";
cout << endl;
int_array[12] = 100; // Calls overloaded array operator
}