c++程序出错 求救

来源:百度知道 编辑:UC知道 时间:2024/06/05 00:18:43
#include<iostream.h>
class math
{ private:
int b[2][2];
public:
int a[2][2];
math(int *p)
{ for(int i=0;i<2;i++)
for(int j=0;j<2;j++)
a[i][j]=*(p+i)+j;
}
void print()
{ for (int i=0;i<2;i++)
{cout<<endl;for(int j=0;j<2;j++) cout<<b[i][j];
}
}
math operator+(math x)
{ math temp;
for(int i=0;i<2;i++)
for(int j=0;j<2;j++)
temp.b[i][j]=x.a[i][j]+a[i][j];
return temp;
}
math operator-(math x)
{ math temp;
for(int i=0;i<2;i++)
for(int j=0;j<2;j++)
temp.b[i][j]=x.a[i][j]-a[i][j];
return temp;
}
};
int main()
{math A,B,C,D;
int c[2][2],b[2][2]={(1,1),(1,1)};
for(int i=0;i<2;i++)
for(int j=0;j<2;j++)
cin>>c[i][j];
A(c);
B(b);
C=A+B;
D

#include<iostream.h>
class math
{
private:
int b[2][2];
public:
int a[2][2];
math(){};///////////////////////////////////////////////////1
//math(int *p=0) 这个相当于一维数组的指针,应该用二维的,换成下句
math(int p[2][2])
{
for(int i=0;i<2;i++)
for(int j=0;j<2;j++)
//a[i][j]=(*(p+i)+j);
a[i][j]=*(*(p+i)+j);
}
void print()
{
for (int i=0;i<2;i++)
{
cout<<endl;for(int j=0;j<2;j++) cout<<b[i][j];
}
}
math operator+(math x)
{
math temp; //用到无参数的构造函数,需要加这个函数:math(){};//////////////////////////1
for(int i=0;i<2;i++)
for(int j=0;j<2;j++)
temp.b[i][j]=x.a[i][j]+a[i][j];
return temp;
}
math operator-(math x)
{
math temp;
for(int i=0;i<2;i++)
for(int j=0;j<2;j++)
temp.b[i][j]=x.a[i][j]-a[i][j];
ret