I have a class (A) that (indirectly through a static method) accesses a static variable (STL container) in another class (B) in its constructor and destructor.
Objects can be global, global constants, static members of another class stored in other classes (which can themselves have global or static instances), or basically somewhere else there can be a C ++ object.
If object A is built before the static members in B or collapses after the static members in B, this will lead to a failure at some point (usually this is a violation of access rights).
Is there a way to ensure that all instances of class A (except those that have leaked because by definition they are "lost" and therefore will not be destroyed in any way) are built after and destroyed before the static variable B?
I saw some solutions for creating / destroying a specific variable before / after another, but not a general case of all instances of this type, so I'm not sure how to approach this.
source
share