// temparr.cpp -example of array without templates #include class ArrayList{ private: int *arr; int arrSize; public: ArrayList(int sizeIn = 5); ArrayList (const ArrayList &other); ~ArrayList(); ArrayList &operator=(const ArrayList &other); int &operator[](int index); const int &operator[](int index) const; int getSize() const; private: void copy(const ArrayList &other); void init(); void freeMem(); }; // default constructor ArrayList::ArrayList(int sizeIn):arrSize(sizeIn){ if (arrSize < 0) arrSize = 5; arr = new int[arrSize]; } // copy constructor ArrayList::ArrayList(const ArrayList &other){ copy(other); } // overloaded operator= ArrayList & ArrayList::operator=(const ArrayList &other){ if(this != &other){ freeMem(); copy(other); } return *this; } // destructor ArrayList::~ArrayList(){ freeMem(); } // copy helper void ArrayList::copy(const ArrayList &other){ init(); arrSize = other.arrSize; arr = new int[arrSize]; } // init helper void ArrayList::init(){ arr = NULL; arrSize = 0; } // freeMem helper void ArrayList::freeMem(){ delete [] arr; arr = NULL; // to be safe } // operator[] non-const version int & ArrayList::operator[](int index){ return arr[index]; } // operator= const version const int & ArrayList::operator[](int index) const{ return arr[index]; } // size int ArrayList::getSize() const{ return arrSize; } main(){ ArrayList list(10); for(int i = 0; i < 10 ; i++){ list[i] = 2*i; cout << list[i] << " "; } cout << endl; return 0; }