diff --git a/main.cpp b/main.cpp index b4cc933..3f21ff6 100644 --- a/main.cpp +++ b/main.cpp @@ -7,9 +7,13 @@ int main() Matrix a(3,2); a.Randomize(); + Matrix b = a; a.Print("A"); - a.Transpose().Print("Transposed"); + b.Print("B"); + + Matrix result = a + &b; + result.Print("A + B"); return 0; } \ No newline at end of file diff --git a/matrices.h b/matrices.h index 20bcd9a..7b043d6 100644 --- a/matrices.h +++ b/matrices.h @@ -14,6 +14,8 @@ class Matrix{ inline void Set(float); + inline Matrix Swap(const Matrix*); + inline void Multiply(float); inline Matrix Multiply(const Matrix*); @@ -40,8 +42,11 @@ class Matrix{ }; Matrix Matrix::operator=(const Matrix* other){ - this->values = other->values; - return *this; + return this->Swap(other); +} + +Matrix Matrix::operator+(const Matrix* other){ + return this->Add(other); } // Constructs a zero matrix @@ -59,6 +64,11 @@ Matrix::Matrix(const Matrix* other){ this->values = other->values; } +Matrix Matrix::Swap(const Matrix* other){ + this->values = other->values; + return *this; +} + void Matrix::Hadamard(const Matrix* other){ // Matrices need to be the same size assertm(this->values.size() == other->values.size() &&