将写好的一个运算符重载为成员函数的代码改为友元函数,就出现这种情况,这是哪里错了呢
矩阵加法的代码:#include<iostream>
using namespace std;
class JZ
{
private:
int hang;
int lie;
int a[100][100];
public:
JZ (int i,int j,int c[100][100])
{hang=i;
lie=j;
int h,l;
for(h=0;h<hang;h++)
for(l=0;l<lie;j++)
a[h][l]=c[h][l];
}
friend JZ operator + (JZ one,JZ two)
{int i,j;
for(i=0;i<hang;i++)
for(j=0;j<lie;j++)
a[i][j]=one.a[i][j]+two.a[i][j];
return (JZ (hang,lie,a) );
}
void show()
{int i,j;
for(i=0;i<hang;i++)
{
for(j=0;j<lie;j++)
cout<<a[i][j]<<'\t';
cout<<endl;
}
}
};
void main()
{ int a[100][100],b[100][100];
int i,j,m,n;
cout<<"该矩阵为几行几列?"<<endl;
cin>>i>>j;
cout<<"矩阵a:"<<endl;
for(m=0;m<i;m++)
for(n=0;n<j;n++)
cin>>a[m][n];
cout<<"矩阵b:"<<endl;
for(m=0;m<i;m++)
for(n=0;n<j;n++)
cin>>b[m][n];
JZ one(i,j,a);
JZ two(i,j,b);
JZ three=one+two;
three.show();
}
报错为:
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 时出错.