-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimplematrix.cpp
More file actions
71 lines (47 loc) · 1.4 KB
/
simplematrix.cpp
File metadata and controls
71 lines (47 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#IFNDEF __SIMPLE_MATRIX_CPP
#DEFINE __SIMPLE_MATRIX_CPP
#include "SimpleMatrix.h"
//Default Constructor
template <typename Type>
SimpleMatrix<Type> :: SimpleMatrix() {
//No Need for implementation, as the vector "mat"
//will create the necessary storage
}
//Constructor with row/col specification and default/initial value to be filled in the matrix
template <typename Type>
SimpleMatrix<Type> :: SimpleMatrix(const int& rows, const int& rows, const Type& val){
for (int i = 0; i < rows; ++i)
{
std::vector<Type> col_vec(cols,val);
mat.push_back(col_vec);
}
}
//Copy Constructor
template <typename Type>
SimpleMatrix<Type> :: SimpleMatrix(const SimpleMatrix<Type>& _rhs){
mat = _rhs.get_mat();
}
//Overloaded assignment operator
template <typename Type>
SimpleMatrix<Type>& SimpleMatrix<Type> :: operator = (const SimpleMatrix<Type>& _rhs){
if(this==&rhs) return *this; //Handling assignment to self
mat=_rhs.get_mat();
return *this;
}
//Destructor
template <typename Type>
SimpleMatrix<Type> :: ~SimpleMatrix()
{
//No need for implementation as there is no manual dynamic memory allocation
}
//Matrix access method, via copying
template <typename Type>
SimpleMatrix<Type> SimpleMatrix<Type> :: get_mat() const {
return mat;
}
//Matrix acces method via row and column index
template <typename Type>
Type& SimpleMatrix<Type> :: value(const int& row, const int& col){
return mat[row][col];
}
#ENDIF