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 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测