What am I doing wrong??

This partial code is for a matrix calculator and I'm trying to overload the operator << so that it will be written to another file. I'm getting this error
"qualifiers dropped in binding reference of type "Matrix &" to initializer of type "const Matrix"."


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
ostream& operator<< (ostream& os, const Matrix& a)
//overload the stream insertion operator << 
{
	int rows, columns;
	os << rows << columns;
	if  (!os) return os;

	Matrix temp(rows,columns);

	for (int i = 0; i < rows; ++i) {
		for (int j = 0; j < columns; ++j) {
			os << temp.matrix[i][j];
			if (!os) return os;
		}
	}
	temp.swap(a);//what does swap do?? <<<-----I'm getting an error here
	return os;
}

istream& operator>> (istream& is, Matrix& a)
	//overload the stream extraction operator >> 
{
	int rows, columns;
    is >>rows>>columns;
    if (!is) return is;

    Matrix temp(rows,columns);

	for (int i = 0; i < rows; ++i) {
		for (int j = 0; j < columns; ++j) {
			is >> temp.matrix[i][j];
			if (!is) return is;
		}
	}
	temp.swap(a);
	return is;
}



Any suggestions please let me know. Thanks I appreciate it!
Last edited on
I did not see all the code snip but what is it a stupid code?

1
2
	int rows, columns;
	os << rows << columns;
And I do not know what swap is doing here

temp.swap(a);//what does swap do?? <<<-----I'm getting an error here

but it is obvious that you may not change a const object passed to function by const reference.
Last edited on
$ dict swap
To exchange (usually two things of the same kind)
that's what `swap' ought to do.
Topic archived. No new replies allowed.