在另一个类中创建一个类内存分配
如果我有几个类,比如说一个是基类,并且它是在另一个类中创建的,如果“外部”类是使用 new 运算符创建的,但在其内部创建的类不是,那么它会位于堆栈还是堆上't。例如:
class baseclass { //code here }; class outside { baseclass mybase; //more code }; int main() { outside *myclass; myclass = new outside; }
mybase 也分配在堆上吗? 谢谢!
If I have a few classes, say one is a base class and it is created inside another class, will it be located on the stack or heap if the "outside" class is created with the new operator but the class created inside of it isn't. For example:
class baseclass { //code here }; class outside { baseclass mybase; //more code }; int main() { outside *myclass; myclass = new outside; }
Is mybase allocated on the heap as well?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的。这是正确的。但它不需要额外的新建或删除。
Yes. That's correct. It does not require an additional new or delete for it though.
您的
outside
和baseclass
是在同一内存区域创建的。Your
outside
andbaseclass
are created at the same memory area.