From 413f8bf02b7522181d2b9b3fc165b2e56b52a159 Mon Sep 17 00:00:00 2001 From: ADOBbIU <116001723+ADOBbIU@users.noreply.github.com> Date: Wed, 20 Nov 2024 22:55:59 +0500 Subject: [PATCH] =?UTF-8?q?=D0=9B=D0=B0=D0=B7=D1=83=D1=82=D0=BA=D0=B8?= =?UTF-8?q?=D0=BD=20=D0=9C.=D0=9A.=201?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- task1/matrix.hpp | 44 +++++++++++++++++++++++++++++++++++--------- 1 file changed, 35 insertions(+), 9 deletions(-) diff --git a/task1/matrix.hpp b/task1/matrix.hpp index d314915..d64e883 100644 --- a/task1/matrix.hpp +++ b/task1/matrix.hpp @@ -1,18 +1,44 @@ #pragma once +#include +#include +#include -class Matrix -{ +class Matrix { public: - Matrix() = default; - Matrix(int numRows, int numCols); + Matrix() : num_rows(0), num_cols(0) {} + explicit Matrix(int rows, int cols); + + Matrix(const Matrix& other) = default; + Matrix& operator=(const Matrix& other) = default; + + Matrix(Matrix&& other) noexcept : num_rows(other.num_rows), num_cols(other.num_cols), data(std::move(other.data)) { + other.num_rows = 0; + other.num_cols = 0; + } + Matrix& operator=(Matrix&& other) noexcept { + if (this != &other) { + num_rows = other.num_rows; + num_cols = other.num_cols; + data = std::move(other.data); + other.num_rows = 0; + other.num_cols = 0; + } + return *this; + } - void Reset(int numRows, int numCols); + void Reset(int rows, int cols); + int At(int row, int col) const; int& At(int row, int col); - const int& At(int row, int col) const; int GetRows() const; int GetCols() const; - bool operator==(const Matrix& m2); - bool operator!=(const Matrix& m2); - Matrix operator+(const Matrix& m2); + + friend bool operator==(const Matrix& lhs, const Matrix& rhs); + friend bool operator!=(const Matrix& lhs, const Matrix& rhs); + friend Matrix operator+(const Matrix& lhs, const Matrix& rhs); + +private: + int num_rows; + int num_cols; + std::vector> data; };