私は次のコードを持っています:
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)
は悪く見えますが、大丈夫、これは私がそれで何もできない場合です。
ありがとうございました。