Iovebiancheng 2021-07-27 10:18 采纳率: 100%
浏览 30
已结题

不知道那出现错误,求解

img

img

img

  • 写回答

1条回答 默认 最新

  • 浪客 2021-07-27 10:36
    关注

    name = new char[strlen(temp.name) + 1];
    new的是数组,要用[]

    class study {
    
    public:
        char* name, * url;
    
    public:
        study(const char* name, const char* url) {
            this->name = new char[strlen(name) + 1];
            this->url = new char[strlen(url) + 1];
            if (this->name)
                strcpy(this->name, name);
    
            if (this->url)
                strcpy(this->url, url);
        }
    
        study(study& temp) {
            name = new char[strlen(temp.name) + 1];
            url = new char[strlen(temp.url) + 1];
            if (name)
                strcpy(name, temp.name);
            if (url)
                strcpy(url, temp.url);
        }
        study& operator =(study& temp) {
            delete[] name;
            delete[] url;
            name = new char[strlen(temp.name) + 1];
            url = new char[strlen(temp.url) + 1];
            if (name)
                strcpy(name, temp.name);
            if (url)
                strcpy(url, temp.url);
    
            return *this;
        }
    };
    
    int main()
    {
        study a("试试", "www.shishi.com");
        cout << a.name << ":" << a.url << endl;
        study b = a;
        cout << b.name << ":" << b.url << endl;
        study c("看看", "www.kankan.com");
        b = c;
        cout << b.name << ":" << b.url << endl;
        system("pause");
        return 0;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 8月4日
  • 已采纳回答 7月27日
  • 创建了问题 7月27日

悬赏问题

  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应