I have the following code:
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;
}
Then somewhere I call Foo
several times in a sequence
Why does the vector object gets constructed on every Foo()
call and why is the destructor called right after static ...
declaration?
Update:
I was trying to implement function once calling mechanism and I thought that writing something like
static core::CallOnce(parameters)
where CallOnce
is a class name would be very nice.
To my mind writing static core::CallOnce call_once(parameters)
looks worse, but okay, this is the case I can't do anything with it.
Thank you.