// MT3Q6.cpp - traits #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& 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() { double temp1[] = { 0, 0.5, 1.0, 1.5, 2.0 }; Array arr1(temp1); display(arr1); std::cout << "\n sum = " << sum(arr1) << "\n"; int temp2[] = { 1, 2, 3, 4, 5 }; Array arr2(temp2); display(arr2); std::cout << "\n sum = " << sum(arr2) << "\n\n"; }