Home > Back-end >  Why the compiled tip <overload mistake......
Why the compiled tip <overload mistake......

Time:09-20

#include
#include
#include
using namespace std;

//____qcodep____
The class Matrix
{
Public:
Matrix (int x, int y) {
R=x;
C=y;
};
Friend istream& The operator & gt;> (istream& , Matrix&);
Friend ostream& The operator & lt; & lt; (ostream& , Matrix&);
Matrix operator + (Matrix & amp; M2);
Matrix operator - (Matrix & amp; M2);
Matrix operator * (Matrix & amp; M2);
Private:
Int r, c;
Int j [1000] [1000].
};
Istream& The operator & gt;> (istream& In Matrix& M) {
Int I, j;
for(i=1; i<=m.r; I++) {
for(j=1; J<=m.c. J++) {
In> M.M [I] [j];
}
}
Return in;
}
Ostream& The operator & lt; & lt; (ostream& Out, Matrix& M) {
If (m.r==1) {
Out<& lt; Setw (6) & lt; & lt;" Invalid operation!" & lt; & lt; endl;
return out;
}
The else {
Int I, j;
for(i=1; i<=m.r; I++) {
for(j=1; J<=m.c. J++) {
Out<& lt; Setw (6) & lt; & lt; M.M [I] [j];
If (j==m.c)
Out<& lt; endl;
}
}
return out;
}
}
Matrix Matrix: : operator + (Matrix & amp; M2) {
If (r==m2. R & amp; & C==m2. C) {
Int I, j;
for(i=1; i<=r; I++) {
for(j=1; J<=c; J++) {
M [I] [j] +=m2. M [I] [j];
}
}
return *this;
}
The else {
Return Matrix (1, 1);
}
}
Matrix Matrix: : operator - (Matrix & amp; M2) {
If (r==m2. R & amp; & C==m2. C) {
Int I, j;
for(i=1; i<=r; I++) {
for(j=1; J<=c; J++) {
M [I] [j] -=m2. M [I] [j];
}
}
return *this;
}
The else {
Return Matrix (1, 2);
}
}
Matrix Matrix: : operator * (Matrix & amp; M2) {
If (c==m2. R) {
Int I, j, k;
Matrix temp (r, m2. C);
for(i=1; i<=r; I++) {
for(j=1; J<=c; J++) {
Temp. M [I] [j]=0;
For (k=1; K<=c; K++) {
Temp. M [I] [j] +=(M [I] [k] + m2. M [k] [j]);
}
}
}
Return temp.
}
The else
Return Matrix (1, 3);
}
Int main () {
Int r, c;

cin> R> c;
If (r<1 | | c<1) {
Cout<& lt;" Input error. "& lt; & lt; endl;
The exit (1);
}
Matrix A (r, c);
Cin & gt;> A;

cin> R> c;
If (r<1 | | c<1) {
Cout<& lt;" Input error. "& lt; & lt; endl;
The exit (1);
}
Matrix B (r, c);
Cin & gt;> B;

Cout<& lt;" A + B: "& lt; & lt; endl;
Cout & lt; & lt; A + B & lt; & lt; endl;

Cout<& lt;" A - B: "& lt; & lt; endl;
Cout & lt; & lt; A - B & lt; & lt; endl;

Cout<& lt;" A * B: "& lt; & lt; endl;
Cout & lt; & lt; A * B & lt; & lt; endl;

return 0;
}

CodePudding user response:

Const T&

CodePudding user response:

What is T...

CodePudding user response:

T refers to your class
  • Related