矩阵相加重载编译出错
#include<iostream>using namespace std;
class M23
{
public:
//M23 operator +(M23 &c2);
friend M23 operator+(M23&,M23&);
friend ostream& operator<<(ostream&,const M23&);
friend istream& operator>>(istream&,const M23&);
private:
int a[2][3];
};
ostream& operator<<(ostream& out,const M23& m)
{
for(int i=0;i<2;i++)
{
for(int j=0;j<3;j++)
{
out<<m.a[i][j];
}
return out;
}
}
istream& operator>>(istream& in,const M23& m)
{
for(int i=0;i<2;i++)
{
for(int j=0;j<3;j++)
in>>m.a[i][j];
}
return in;
}
M23 operator+(M23& m1,M23& m2)
{
M23 m;
for(int i=0;i<2;++i)
for(int j=0;j<3;++j)
m.a[i][j] = m1.a[i][j] + m2.a[i][j];
return m;
}
/*M23 M23::operator +(M23 &c2)
{
}*/
int main()
{
M23 m1,m2,m3;
cin>>m1>>m2;
m3 = m1 + m2;
cout<<m1<<endl<<m2<<endl<<m3<<endl;
return 0;
}
--------------------Configuration: 10_4 - Win32 Debug--------------------
Compiling...
10_4.cpp
F:\Study Garden\上机内容\c++\10_4\10_4.cpp(7) : fatal error C1001: INTERNAL COMPILER ERROR
(compiler file 'msc1.cpp', line 1786)
Please choose the Technical Support command on the Visual C++
Help menu, or open the Technical Support help file for more information
执行 cl.exe 时出错.
10_4.obj - 1 error(s), 0 warning(s)