我有以下代码:
void Foo() {
static std::vector<int>(3);
// Vector object is constructed every function call
// The destructor of the static vector is invoked at
// this point (the debugger shows so)
// <-------------------
int a;
}
然后在某个地方我按顺序调用Foo
了几次
为什么每次Foo()
调用都会构造向量对象,为什么在声明后立即调用析构函数static ...
?
更新:
我试图在调用机制后实现函数,我认为编写类似的东西
static core::CallOnce(parameters)
哪里CallOnce
是一个类名会很好。
在我看来,写作static core::CallOnce call_once(parameters)
看起来更糟,但是好吧,在这种情况下我无能为力。
谢谢你。