#define_crt_secure_no_warnings#include<iostream>using namespacestd;template<classT1>classperson{ Public: Person (intLen) { This->len =Len; This->t =NewT1[len]; if(! This-t) {cout<<"failed"<<Endl; Exit (1); } for(inti =0; i < Len; i++) { ( This->T) [I] =0; }} person (intLen, t1*t) { This->len =Len; This->t =NewT1[len]; if(! This-t) {cout<<"failed"<<Endl; Exit (1); } strcpy ( This-T, T); } T1&operator[](inti); ~Person () {if( This->t! =NULL) { Delete[] t; T=NULL; } } Public: T1*T; intLen;}; Template<classT1>T1& Person<t1>::operator[](inti) { if(I <0|| i > This->len-1) {cout<<"out of bounds."<<Endl; Exit (2); } return( This-6) [i];}voidMain () { person<int> A1 (Ten); person<Char> A2 (Ten,"123456789"); cout<<"----------"<<Endl; for(inti =0; I <Ten; i++) {A1[i]= i +1; } for(intI0); I <Ten; i++) {cout<< A1[i] <<Endl; } cout<<"---------------"<<Endl; cout<< a2.t <<Endl; return;}
C + + Template implementation Array class