暂时有bug。
#include<bits/stdc++.h>
using namespace std;
namespace MaTrIx{
struct Matrix{
signed n,m;
signed mp[1010][1010];
const signed*operator[](const signed&pos)const{return mp[pos];}
signed*operator[](const signed&pos){return mp[pos];}
Matrix(const signed&_N=0,const signed&_M=0):n(_N),m(_M){}
Matrix(const Matrix&mat):n(mat.n),m(mat.m){
for(signed i=1;i<=n;i++)
for(signed j=1;j<=m;j++) mp[i][j]=mat[i][j];
}
const Matrix operator-()const{
Matrix ret(n,m);
for(signed i=1;i<=n;i++)
for(signed j=1;j<=m;j++) ret[i][j]=-mp[i][j];
return ret;
}
const Matrix operator+(const Matrix&mat)const{
if(n!=mat.n||m!=mat.m) throw invalid_argument("The size of the matrixs isn't the same");
Matrix ret(n,m);
for(signed i=1;i<=n;i++)
for(signed j=1;j<=m;j++) ret[i][j]=mp[i][j]+mat[i][j];
return ret;
}
const Matrix operator-(const Matrix&mat)const{
if(n!=mat.n||m!=mat.m) throw invalid_argument("The size of the matrixs isn't the same");
Matrix ret(n,m);
for(signed i=1;i<=n;i++)
for(signed j=1;j<=m;j++) ret[i][j]=mp[i][j]-mat[i][j];
return ret;
}
const Matrix operator*(const signed&c)const{
Matrix ret(n,m);
for(signed i=1;i<=n;i++)
for(signed j=1;j<=m;j++) ret[i][j]=c*mp[i][j];
return ret;
}
const Matrix operator*(const Matrix&mat)const{
if(m!=mat.n) throw invalid_argument("The size of the matrixs doesn't match");
Matrix ret(n,mat.m);
for(signed i=1;i<=n;i++)
for(signed k=1;k<=m;k++)
for(signed j=1;j<=mat.m;j++) ret[i][j]+=mp[i][k]*mat[k][j];
return ret;
}
const Matrix operator+=(const Matrix&mat){return (*this)=(*this)+mat;}
const Matrix operator-=(const Matrix&mat){return (*this)=(*this)-mat;}
const Matrix operator*=(const signed&c){return (*this)=(*this)*c;}
const Matrix operator*=(const Matrix&mat){return (*this)=(*this)*mat;}
};
}using namespace MaTrIx;
signed main(){
Matrix a(2,3),b(3,4);
a*b;
return 0;
}