Yip*_*Yay 0 c++ static members
我有以下代码:
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;
}
Run Code Online (Sandbox Code Playgroud)
然后在某个地方我Foo按顺序多次打电话
为什么vector对象在每次Foo()调用时都被构造,为什么在static ...声明后调用析构函数呢?
更新:
我试图实现函数一次调用机制,我认为写的东西就像
static core::CallOnce(parameters)CallOnce类名称在哪里会非常好.
在我看来写作static core::CallOnce call_once(parameters)看起来更糟,但没关系,这是我无法用它做任何事情的情况.
谢谢.
Jam*_*lis 12
您的变量需要一个名称:
static std::vector<int> my_static_vector(3);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
244 次 |
| 最近记录: |