// MT4Q2b.cpp - Array class with iterator #include #include template class Array { public: typedef T value_type; typedef T* iterator; Array() : pArray(new T[Size]) {} Array(T* pT) : pArray(new T[Size]) { for(int i=0; i& arr) { if(Size != arr.size()) throw ("not same size"); pArray = new T[Size]; for(int i=0; i& operator=(const Array& arr) { if(Size != arr.size()) throw ("not same size"); if(this == &arr) return *this; pArray = new T[Size]; for(int i=0; i void display(Cont& c) { Cont::iterator iter, last = c.end(); last = --last; std::cout << "\n "; for(iter = c.begin(); iter != last; ++iter) std::cout << *iter << ", "; std::cout << *last << "\n"; } template typename Cont::value_type sum(Cont& c) { Cont::iterator iter; Cont::value_type sum_ = Cont::value_type(); for(iter = c.begin(); iter != c.end(); ++iter) sum_ += *iter; return sum_; } int main() { std::string temp1[] = { "aardvark", "armadillo", "koala", "platypus", "vole" }; Array arr1(temp1); display(arr1); std::cout << "\n sum = " << sum(arr1) << "\n"; std::cout << "\n copying:"; Array arr2 = arr1; display(arr2); std::cout << "\n assigning:"; arr1 = arr2; display(arr1); std::cout << "\n"; }