- //文件名:CHAPTER3-10.cpp
- #include<iostream.h>
- template<class T>
- class Array
- { T *ar;
- public:
- Array(int c){ar=new T[c];}
- void init(int n,T x){ar[n]=x; }
- T& operator[](int n){return ar[n];}
- };
- void main()
- { Array<int> array(5);
- cout<<"Please input every element's value:"<<endl;
- for(int i=0;i<5;i++){ cout<<"No."<<i+1<<':'; cin>>array[i]; }
- }