From 770263a8b8a19a4b121bac0783c935520b39d545 Mon Sep 17 00:00:00 2001 From: Micke Nordin Date: Sun, 17 Jul 2022 13:19:22 +0200 Subject: [PATCH] Copy constructor --- matrix.hpp | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/matrix.hpp b/matrix.hpp index 20bce4a..5e4d9de 100644 --- a/matrix.hpp +++ b/matrix.hpp @@ -11,12 +11,20 @@ private: vector *cols; public: - matrix(const long long num_cols, const long long num_rows) { - this->num_cols = num_rows; - this->num_rows = num_cols; - this->cols = (vector *)calloc(sizeof(vector), num_rows); - for (long long i = 0; i < num_rows; i++) { - this->cols[i] = vector(num_cols); + matrix(const long long num_rows, const long long num_cols) { + this->num_cols = num_cols; + this->num_rows = num_rows; + this->cols = (vector *)calloc(sizeof(vector), num_cols); + for (long long i = 0; i < num_cols; i++) { + this->cols[i] = vector(num_rows); + } + } + matrix(const matrix &m) { + this->num_cols = m.num_cols; + this->num_rows = m.num_rows; + this->cols = (vector *)calloc(sizeof(vector), m.num_cols); + for (long long i = 0; i < m.num_cols; i++) { + this->cols[i] = m[i]; } } ~matrix() {