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

后端 未结 5 922
不思量自难忘°
不思量自难忘° 2021-02-15 02:11

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:29

    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).

提交回复
热议问题