#include<iostream> using namespace std; template<typename T> class CArray { public: CArray():m_size(0),m_data(NULL){} CArray(size_t size):m_size(size),m_data(new T[size+1]()){} ~CArray() { if(m_data) { delete []m_data; m_data = NULL; } } public: T &operator [](int i) { if(i >=m_size || m_data == NULL) throw "error"; return m_data[i]; } const T& operator [](int i)const { if(i>= m_size || m_data == NULL) throw "error"; return m_data[i]; } operator T *const(){ return m_data;} operator const T*const() const {return m_data;} private: CArray(const CArray&){} CArray &operator = (const CArray &); private: size_t m_size; T *m_data; }; int main() { CArray<int> a(3); a[0] = 1; *(a+1) = 2; cout<<a[0]<<endl; cout<<a[1]<<endl; cout<<a[2]<<endl; }