= operator uses new Swap function and added + operator
This commit is contained in:
parent
e0d6d480da
commit
7e35b218d9
6
main.cpp
6
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;
|
||||
}
|
14
matrices.h
14
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() &&
|
||||
|
Loading…
x
Reference in New Issue
Block a user