【发布时间】:2010-06-17 15:21:13
【问题描述】:
可能重复:
What is the lifetime of a static variable in a C++ function?
假设我们有这样的代码:
Some class {
Some() { // the ctor code }
};
Some& globalFunction()
{
static Some gSome;
return gSome;
}
“ctor 代码”究竟是什么时候执行的?至于在main()之前还是我们第一次调用'globalFunction()'时的普通静态变量?
在不同平台和不同编译器(cl、gcc、...)上的表现如何?
谢谢
-hb-
【问题讨论】:
标签: c++ static constructor local