All pastes #2084447 Raw Edit

Something

public text v1 · immutable
#2084447 ·published 2011-09-29 02:18 UTC
rendered paste body
template <class U>
Matrix<U> operator+(const Matrix<U> &lhs, const Matrix<U> &rhs)
{

    if((lhs.rows != rhs.rows) || (lhs.columns != rhs.columns) ){
    //cannot perform addition, return an empty matrix
    cout << "Incorrect matrix dimensions" << endl;
    Matrix<U> Sum("AddError", 0, 0);
    return Sum;
    }

    //if sizes are consitent create new matrix and add up the entries
    Matrix<U> Sum("Sum", lhs.rows, lhs.columns);
    //copy entries from source matrix
    for(int i = 0; i < Sum.rows; i ++)
        for(int j = 0; j < Sum.columns; j++){
            Sum.ppDynMatrix[i][j] = lhs.ppDynMatrix[i][j] + rhs.ppDynMatrix[i][j];
        }
        Matrix_print(Sum);
    return (Sum);
}