数组和矩阵-1要点.ppt

数组和矩阵-1要点

* Matrix 操作符‘()’ templateclass T T MatrixT::operator()(int i, int j) const {// 返回一个指向元素(i,j)的引用 if (i 1||irows||j1||jcols) throw OutOfBounds(); return element[(i-1)*cols +j-1]; } 读 P139 程序4-13 Matrix 构造函数 读 P140 程序4-15 Matrix 减法操作符 * Matrix 操作符‘*’ templateclass T MatrixT MatrixT:: operator*(const MatrixT m) const {// 矩阵乘法,返回w =(*this)*m. if (cols!=m.rows) throw SizeMismatch(); MatrixT w(rows, m.cols); // 结果矩阵 // 为*this, m和w定义游标 // 并设定初始位置为(1,1) int ct=0, cm=0, cw=0; * Matrix 操作符 ‘*’ for (int i=1; i=rows; i++) { // 对所有的i和j计算w(i,j) for (int j=1; j=m.cols; j++) { // 计算出结果的

文档评论(0)

1亿VIP精品文档

相关文档