钰爱& 2023-05-06 22:13 采纳率: 0%
浏览 15

c++:运行时会显示:写入权限冲突,应该怎么改代码才能正常运行

运行时会显示:写入权限冲突,应该怎么改代码才能正常运行
题目:编写一个程序,用成员函数重载运算符+和-,将两个一维数组相加和相减,要求第一个一维数组的值由构造函数设置,另一个一维数组的值由键盘输入。

c++

#include<iostream>
using namespace std;
class Shape
{
private:
    int *a;
public:
    Shape();
    Shape(int *b)
    {
        a = b;
    }
    void show();
    Shape operator +(Shape &c);
    Shape operator -(Shape &c);
};
Shape::Shape()
{
    a = NULL;
}
void Shape::show()
{
    for (int i = 0; i < 4; i++)
    {
        cout << a[i] << "    ";
    }
    cout << endl;
}
Shape Shape::operator + (Shape &c)
{
    Shape temp;
    for (int i = 0; i < 4; i++)
    {
        temp.a[i] = a[i] + c.a[i];
    }
    return temp;
}
Shape Shape::operator -(Shape &c)
{
    Shape temp;
    for (int i = 0; i < 4; i++)
    {
        temp.a[i] = a[i] - c.a[i];
    }
    return temp;
}
int main()
{
    int a[4] = { 1,2,3,4 };
    int b[4];
    Shape obj(a);
    obj.show();
    cout<<"pleace input 4 numbers:"<<endl;
    for(int j=0;j<4;j++)
    {
        cin>>b[j];
    }
    Shape obj1(b), obj2;
    obj2 = obj1 + obj;
    obj2.show();
    system("pause");
    return 0;
}


  • 写回答

1条回答 默认 最新

  • threenewbee 2023-05-06 22:20
    关注

    可能是之前的程序运行了没有关闭,把exe文件锁定了无法写入,关闭下之前云心的程序再编译。或者注销windows登录,重新打开,再编译。

    评论

报告相同问题?

问题事件

  • 创建了问题 5月6日

悬赏问题

  • ¥20 校园二手交易小程序搭建
  • ¥15 请问在ubuntu用conda创建环境报错怎么能解决
  • ¥15 STM32CubeMX/proteus按键控制指示灯颜色切换
  • ¥20 python,计算区位熵和扩张指数
  • ¥15 Python环境配置
  • ¥15 大四学生的困惑,有偿提问!
  • ¥15 解决页面无法编入索引:被“noindex”标签排除的问题?
  • ¥15 arduino测量电阻
  • ¥15 快手uid转快手号谁能解决 需要开发
  • ¥15 iis部署Django时css不生效,来个真人,ai不好使