#风也温柔# 2021-05-15 17:59 采纳率: 50%
浏览 17
已采纳

重载使数组相加减,这个错误怎么改

#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; 
}

  • 写回答

2条回答 默认 最新

  • 关注

    class array{少了结束的右括号,在类结束的地方加上。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题