rendered paste bodytemplate <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);
}