#include
#include
using namespace std;
template class MyClass {
T a[size]; // size of array is passed in size
public:
MyClass() {
register int i;
for(i=0; i }
T &operator[](int i);
};
template
T &MyClass::operator[](int i)
{
if(i<0 || i> size-1) {
cout << "\nIndex value of ";
cout << i << " is out-of-bounds.\n";
exit(1);
}
return a[i];
}
int main()
{
MyClass intarray;
MyClass doublearray;
MyClass<> defarray;
cout << "int array: ";
for(int i=0; i<100; i++) intarray[i] = i;
for(int i=0; i<100; i++) cout << intarray[i] << endl;
cout << "double array: ";
for(int i=0; i<10; i++) doublearray[i] = (double) i/3;
for(int i=0; i<10; i++) cout << doublearray[i] << endl;
cout << "defarray array: ";
for(int i=0; i<10; i++) defarray[i] = i;
for(int i=0; i<10; i++) cout << defarray[i] << endl;
return 0;
}