如果 this 在函数内声明,它会在堆栈上声明吗? (它是 const 让我想知道的)
void someFunction()
{
const unsigned int actions[8] =
{ e1,
e2,
etc...
};
}
最佳答案
是的,它们在堆栈上。您可以通过查看此代码片段来了解这一点:它必须将销毁消息打印 5 次。
struct A { ~A(){ printf( "A destructed\n" ); } };
int main() {
{
const A anarray [5] = {A()} ;
}
printf( "inner scope closed\n");
}
关于c++ - const 数组是否在存储在堆栈中的函数中声明?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1334069/