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++ 在堆 - 栈上建立对象 | Nature 的博客 #13

Open
NatureLan-sudo opened this issue Sep 13, 2022 · 0 comments
Open

三星 C++ 在堆 - 栈上建立对象 | Nature 的博客 #13

NatureLan-sudo opened this issue Sep 13, 2022 · 0 comments

Comments

@NatureLan-sudo
Copy link
Owner

https://naturelan-sudo.github.io/2022/09/13/%E5%9C%A8%E5%A0%86-%20%E6%A0%88%E5%BB%BA%E7%AB%8B%E5%AF%B9%E8%B1%A1%20%20%20%20-%20%20%20%202022-08-31/#more

**如何限制类的对象只能在堆上创建?如何限制对象只能在栈上创建?**说明:C++ 中的类的对象的建立分为两种:静态建立、动态建立。 静态建立: 由编译器为对象在栈空间上分配内存,直接调用类的构造函数创建对象。例如:A a;动态建立: 使用 new 关键字在堆空间上创建对象,底层首先调用 operator new() 函数,在堆空间上寻找合适的内存并分配;然后,调用类的构造函数创建对象。例如:A *

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

No branches or pull requests

1 participant