Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Matrix {
- private:
- const int M_ROW;
- const int M_COL;
- double** p_matrix;
- public:
- friend Matrix operator+(const Matrix& m1, const Matrix& m2);
- Matrix(const int row, const int col) : M_ROW{ row }, M_COL{ col }, p_matrix{ new double*[M_ROW]}{
- for (int row{ 0 }; row < M_ROW; ++row) {
- p_matrix[row] = new double[M_COL] {};
- }
- };
- Matrix operator+(const Matrix& m1, const Matrix& m2)
- {
- assert(m1.M_ROW == m2.M_ROW);
- assert(m1.M_COL == m2.M_COL);
- Matrix temp{m1.M_ROW, m1.M_COL};
- for (int row{ 1 }; row <= m1.M_ROW; ++row) { // Indexing begins at 1 for irrelevant reasons i.e. ignore
- for (int col{ 1 }; col <= m1.M_COL; ++col) {
- temp(row, col) = m1(row, col) + m2(row, col);
- }
- }
- return temp; // Function returns de-allocated object...
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement