Jump to content

  • Log In with Google      Sign In   
  • Create Account


#ActualAllEightUp

Posted 26 June 2013 - 09:30 PM

Much like the other mentioned items, I'll just expand and clarify:

 

C++ only has two levels (to my understanding which is pretty decent) of static initialization.  The first level are those static/global items which are pod items.  Anything which is a pod item will be initialized to whatever static data is given.  So, a pointer for instance, initialized to nullptr is done before any code is run.  When it comes to items with complex constructors (your map for instance), there is only one guarantee: items in a "module" (i.e. the same c/cpp file) will initialize in order of appearance.  Understanding the actual rules in this is complex and it is easy to find one working case and another non-working case if you didn't understand these rules and abused them.  So, you "could" move your user class below the static definition of the map and probably fix things, unless something else outside of the module accesses it and that is completely undefined behavior. sad.png


#1AllEightUp

Posted 26 June 2013 - 09:29 PM

Much like the other mentioned items, I'll just expand and clarify:

 

C++ only has two levels (to my understanding which is pretty decent) of static initialization.  The first level are those static/global items which are pod items.  Anything which is a pod item will be initialized to whatever static data is given.  So, a pointer for instance, initialized to nullptr is done before any code is run.  When it comes to items with complex constructors (your map for instance), there is only one guarantee: items in a "module" (i.e. the same c/cpp file) will initialize in order of appearance.  Understanding the actual rules in this is complex and it is easy to find one working case and another non-working case if you didn't understand these rules and abused them.  So, you "could" move your user class above the static definition of the map and probably fix things, unless something else outside of the module accesses it and that is completely undefined behavior. :(


PARTNERS