Passing 2D Vector to a function problem

Hello, I've been trying all day on how to pass a 2D Vector to a function using parameters. I've tried passing by reference but I've been getting the error "type 'const Matrix' does not provide a subscript operator". Below is my code, any help would be appreciated!

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
  Driver:
..
	(mat_2) - mat_2;
..
  Implementation:
..
Matrix Matrix::operator-(const Matrix& subtrahend_matrix) const {
..
	Matrix differenceMatrix;
	differenceMatrix.columns = columns;
	differenceMatrix.rows = rows;
	differenceMatrix.setAllValuesToZero();

	if (this->getDimension() == subtrahend_matrix.getDimension()) {
		cout << "Matrix subtraction result:" << endl;
		for (int i=0; i<rows; i++) {
			for (int j=0; j<columns; j++) {
				differenceMatrix[i][j] = (matrix[i][j] - subtrahend_matrix[i][j]);
			}
		}
	} else {
		cout << "Invalid dimension." << endl;
	}
	return differenceMatrix;
..
}

  header
..
	Matrix operator-(const Matrix& subtrahend_matrix) const;
..
Last edited on
Did you provide operator [][]
@Ats15, what do you mean?
I don't know your code, but I assume that you have a private variable double **mat somewhere. Then you need to define double *operator[](size_t i){return mat[i];}
Topic archived. No new replies allowed.