// Matrix #include #include #include #include //#include ///////////////////////////////////////////////////////////// // class Row // no copy ctor, dtor, or assignment operator needed template class Row { public: Row(int i); T& operator[](int i); T operator[](int i) const; private: int _NumRows; std::vector _rowData; }; template Row::Row(int i) : _NumRows(i) { for(int j=0; j T& Row::operator[](int i) { if(i<0 || _NumRows<=i) throw std::range_error("index out of bounds in Row[]"); return _rowData[i]; } template T Row::operator[](int i) const { if(i<0 || _NumRows<=i) throw std::range_error("index out of bounds in Row[]"); return _rowData[i]; } ///////////////////////////////////////////////////////////// // class Matrix // no copy ctor, dtor, or assignment operator are needed template class Matrix { public: Matrix(int i, int j); Row& operator[](int i); Row operator[](int i) const; int rows(); int cols(); std::string show(); private: int _NumRows, _NumCols; std::vector< Row > _matrixData; }; template Matrix::Matrix(int i, int j) : _NumRows(i), _NumCols(j) { for(int k=0; k temp(j); _matrixData.push_back(temp); } } template int Matrix::rows() { return _NumRows; } template int Matrix::cols() { return _NumCols; } template Row& Matrix::operator [](int i) { if(i<0 || _NumRows<=i) throw std::range_error("index out of range in Matrix::operator[]"); return _matrixData[i]; } template std::string Matrix::show() { std::ostringstream temp(""); for(int i=0; i m(3,4); for(int i=0; i n = m; std::cout << n.show() << "\n\n"; Matrix p(2,5); p = m; std::cout << p.show() << "\n\n"; }