C++ static global non-POD: theory and practice

后端 未结 5 1715
故里飘歌
故里飘歌 2021-02-15 01:49

I was reading the Qt coding conventions docs and came upon the following paragraph:

Anything that has a constructor or needs to run code to be initialized

5条回答
  •  迷失自我
    2021-02-15 02:41

    I don't think static objects constructors can be elided. There is probably a confusion with the fact that a static library is often just a bunch of objects which are token in the executable if they are referenced. Some static objects are designed so that they aren't referenced outside their containing object, and so the object file is put in the executable only if there is another dependency on them. This is not the case in some patterns (using a static object which register itself for instance).

提交回复
热议问题