Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Wongony opened this issue Jun 19, 2024 · 1 comment
Open

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

Wongony opened this issue Jun 19, 2024 · 1 comment

Comments

@Wongony
Copy link

Wongony commented Jun 19, 2024

	~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
Copy link

1031507008 commented Jun 19, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants