Mega Code Archive
Template class with type parameter
#include
#include
using namespace std;
const int SIZE = 10;
template class MyClass {
T a[SIZE];
public:
MyClass(void)
{
int i;
for(i=0; i 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