gpt4 book ai didi

c++ - 一个对象怎么知道它是分配在栈上还是堆上呢?

转载 作者:太空狗 更新时间:2023-10-29 23:09:00 31 4
gpt4 key购买 nike

<分区>

Possible Duplicate:
How can I tell if an object is statically or dynamically allocated on the constructor?

struct Foo {
Foo ();
};

int main ()
{
Foo foo; // Case A
Foo * p_foo = new Foo (); // Case B
}

Foo :: Foo ()
{
if (allocated_on_stack) {
// Case A
}
if (allocated_on_heap) {
// Case B
}
}

Foo 的构造函数能否区分这两种情况?

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