您的位置:首页 > 编程语言 > C语言/C++

c++ 中 local static 对象何时被初始化

2010-09-09 15:50 155 查看
在VS2010中,可以发现,对于primitive type, local static对象在首次调用所在函数是已经初始化完毕,实际上应该在main函数前已经初始化完毕,但对于user defined type(class),其初始化函数是在首次调用所在函数时进行的
class A{
public:
A(int t){ cout << "called from A: constructor" << t << endl;}

protected:
int a;
char b;
};

void local()
{
static int c = 10;
static A a(3);
}
int main()
{
local();
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息