forthespada / InterviewGuide

🔥🔥「InterviewGuide」是阿秀从校园->职场多年计算机自学过程的记录以及学弟学妹们计算机校招&秋招经验总结文章的汇总,包括但不限于C/C++ 、Golang、JavaScript、Vue、操作系统、数据结构、计算机网络、MySQL、Redis等学习总结,坚持学习,持续成长!
https://interviewguide.cn/
Apache License 2.0
5.3k stars 1.42k forks source link

C/C++基础语法 35 浅拷贝和深拷贝 优化 #157

Open Wongony opened 3 months ago

Wongony commented 3 months ago
    ~Student() {
        cout << "~Student " << &name << endl;
        delete name;
        name = NULL;
        }

析构函数中输出 name 指向的地址

    ~Student() {
        cout << "~Student " << static_cast<void*>(name) << endl;
        delete name;
        name = NULL;
        }

//浅拷贝执行结果: //Student //copy Student //~Student 0x7fffed0c3ec0 //~Student 0x7fffed0c3ec0 // Error in `/tmp/815453382/a.out': double free or corruption (fasttop): 0x0000000001c82c20

//深拷贝执行结果: //Student //copy Student //~Student 0x7fffebca9fb0 //~Student 0x7fffebca9fc0

1031507008 commented 3 months ago

这是来自QQ邮箱的假期自动回复邮件。   您好,我最近正在休假中,无法亲自回复您的邮件。我将在假期结束后,尽快给您回复。