gpt4 book ai didi

c++ - 对象成员的位置

转载 作者:太空宇宙 更新时间:2023-11-04 15:47:52 26 4
gpt4 key购买 nike

<分区>

Possible Duplicate:
Are data members allocated in the same memory space as their objects in C++?

如果我这样声明一个对象:

void main() {
MyClass class;
}

它将在堆栈上自动创建。

如果我这样做会发生什么:

class MySecondClass {
private:
MyClass class;
}

成员会在栈上创建吗?如果是这样,如果通过 new 创建 MySecondClass 会怎样?这个成员还会在堆栈上吗?

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com