Do c++ guarantee header-initialized static const member to share a single instance across compile units and libraries?
问题 Let's consider a code header: class uid { public: uid () {++i; } static int i; }; class foo { public: const static uid id; } source: static int uid::i = 0; The header could be included into several source files, shared between compiler units and libraries. Is it guaranteed that there would be only one instance off foo::id , that foo::id::id() would be called once at run-time and, the most important thing, would foo::id.i be the same everywhere in the program and it's libraries? On the other