Regarding the order of destruction of static variables in C ++, are there any guarantees regarding the lifetime of static objects relative to their static member variables?
For example, if I had something like this (insanely simplified example for demo purposes only):
class Object {
static std::vector< Object * > all_objects;
public
Object() {
all_objects.push_back( this );
}
~Object() {
all_objects.erase(
std::remove(all_objects.begin(), all_objects.end(), this),
all_objects.end());
}
};
Would it be “safe” for static objects in different compilation units? That is, is there any guarantee that the member variable all_objectswill adhere to at least as long as any valid object, or there may be a problem when it is all_objectsdestroyed until the last instance of the object?
, (, Python), main()?