weixin_74875144 2023-05-02 15:32 采纳率: 40%
浏览 7

要实现大小不固定的矩阵相加

void get()输入语句报错

#include <iostream>
using namespace std;
class Array
{
private:
    int column,row;
    int *p;
public:
    Array() {}
    Array(int a,int b)
    {column=a;
    row=b;
   p=new int[column*row];}
    
    ~Array()
    {delete []p;}
    
    void get()
    {
        cout<<"请输入矩阵,行为:"<<row<<"列为:"<<column<<endl;
        for(int i=0; i<row; i++)
            for(int j=0; j<column; j++)
                cin>>p[i][j];
    }
    Array operator+(Array &b)
    {  if(row!=b.row || column!=b.column)
        cout<<"不可相加";
        else
       {Array tmp;
        for(int i=0; i<row; i++)
            for(int j=0; j<column; j++)
                tmp.p[i][j]=p[i][j]+t.p[i][j];
        return tmp;}
    }

    void show()
    {
        for(int i=0; i<row; i++)
        {
            for(int j=0; j<column; j++)
            {
                cout<<a[i][j]<<" ";
            }
            cout<<"\n";
        }
        cout<<"------------------"<<endl;
    }
};

int main()
{
    Array c1,c2,c3;
    c1.get();
    c2.get();
    c1.show();
    c2.show();
    c3=c1+c2;
    c3.show();
    return 0;
}

  • 写回答

2条回答 默认 最新

  • 真相重于对错 2023-05-02 16:07
    关注

    你是一级指针,不能用[][]方式

    评论

报告相同问题?

问题事件

  • 创建了问题 5月2日

悬赏问题

  • ¥100 如何寻找到黑客帮助,愿意付丰厚的酬劳
  • ¥15 java代码写在记事本上后在cmd上运行时无报错但又没生成文件
  • ¥15 关于#python#的问题:在跑ldsc数据整理的时候一直抱这种错误,要么--out识别不了参数,要么--merge-alleles识别不了参数(操作系统-linux)
  • ¥15 PPOCRLabel
  • ¥15 混合键合键合机对准标识
  • ¥100 现在不懂的是如何将当前的相机中的照片,作为纹理贴图,映射到扫描出的模型上
  • ¥15 魔霸ROG7 pro,win11.息屏后会显示黑屏,如图,如何解决?(关键词-重新启动)
  • ¥15 有没有人知道这是哪里出了问题啊?要怎么改呀?
  • ¥200 C++表格文件处理-悬赏
  • ¥15 Windows Server2016本地登录失败