#include <iostream>
using namespace std;
#include <iomanip>
const int row=2;
const int col=3;
class array{
private:
int m[row][col];
public:
array(){
for(int i=0;i<row;i++){
for(int j=0;j<col;j++){
m[i][j]=0;
}
}
}
array(int a,int b,int c,int d,int e,int f){
m[0][0]=a;m[0][1]=b;m[0][2]=c;
m[1][0]=d;m[1][1]=e;m[1][2]=f;
}
void getarray(){
cout<<"Please input the data:"<<endl;
for(int i=0;i<row;i++){
for(int j=0;j<col;j++){
cin>>m[i][j];
}
}
}
void show(){
for(int i=0;i<row;i++){
for(int j=0;j<col;j++){
cout<<m[i][j];
}
cout<<"\n";
}
}
array operator +(array &a){
array temp;
for(int i=0;i<row;i++){
for(int j=0;j<col;j++){
temp.m[i][j]=a.m[i][j]+m[i][j];
}
}
return temp;
}
array operator -(array &a){
array temp;
for(int i=0;i<row;i++){
for(int j=0;j<col;j++){
temp.m[i][j]=m[i][j]-a.m[i][j];
}
}
return temp;
}
int main(){
array X(1,2,3,4,5,6);
array Y,Z;
Y.getarray();
cout<<"The X:"<<endl;
X.show();
cout<<"The Y:"<<endl;
Y.show();
cout<<"The X+Y:"<<endl;
Z=X+Y;
Z.show();
cout<<"The X-Y:"<<endl;
Z=X-Y;
Z.show();
return 0;
}
重载使数组相加减,这个错误怎么改
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
2条回答 默认 最新
- CSDN专家-赖老师(软件之家) 2021-05-15 18:03关注
class array{少了结束的右括号,在类结束的地方加上。
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 1无用
悬赏问题
- ¥15 yolov8边框坐标
- ¥15 matlab中使用gurobi时报错
- ¥15 WPF 大屏看板表格背景图片设置
- ¥15 这个主板怎么能扩出一两个sata口
- ¥15 不是,这到底错哪儿了😭
- ¥15 2020长安杯与连接网探
- ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
- ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
- ¥16 mybatis的代理对象无法通过@Autowired装填
- ¥15 可见光定位matlab仿真