-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVectorRef.cpp
More file actions
42 lines (36 loc) · 1.22 KB
/
VectorRef.cpp
File metadata and controls
42 lines (36 loc) · 1.22 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
#include "VectorRef.h"
#include "Matrix.h"
Matrix::VectorRef::VectorRef(BaseVector& orig) : ConstVectorRef(orig) {
//create a reference to the given vector
}
Matrix::VectorRef::VectorRef(Matrix& matrix, int col) : ConstVectorRef(matrix, col) {
//create a reference to the given vector
}
int Matrix::VectorRef::size() const {
//return the number of elements in the vector it refers to
return elements.size();
}
Matrix::BaseVector::value_type& Matrix::VectorRef::at(int index) {
//element access
return *elements.at(index);
}
const Matrix::BaseVector::value_type& Matrix::VectorRef::at(int index) const {
//element access
return *elements.at(index);
}
Matrix::BaseVector::value_type& Matrix::VectorRef::operator[](int index) {
//element access
return *elements[index];
}
const Matrix::BaseVector::value_type& Matrix::VectorRef::operator[](int index) const {
//element access
return *elements[index];
}
Matrix::VectorRef& Matrix::VectorRef::operator=(const BaseVector& rhs) {
//set the value of each element that we refer to
//equal to the value at the corresponding position in rhs
for (int i = 0; i < rhs.size(); i++) {
*elements.at(i) = rhs.at(i);
}
return *this;
}