suppose I have a .cpp
file:
static Foo aFoo;
Foo& staticFoo(){
return aFoo;
}
Foo& singletonFoo(){ // not thread safe in c++-03
static Foo staticFoo;
return staticFoo;
}
and a .h
file that exposes these functions (but not aFoo
directly).
aFoo
is initialized prior to staticFoo
? staticFoo
is destroyed after aFoo
? aFoo
is destroyed after any automatic storage duration variables in my program? singletonFoo
from another translation unit during static initialization then it's unspecified. aFoo
will be destroyed after all local/automatic variables.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.