Static template data members storage

前端 未结 2 499
别跟我提以往
别跟我提以往 2021-01-07 05:51

First I\'ll write example to properly address the question.

First of all, I\'ll declare template to be used to create singleton object (not auto-created): singlet

2条回答
  •  时光取名叫无心
    2021-01-07 06:19

    Though I may misunderstand your question, if storage in your question means definition, my answer might apply.
    As for one definition rule, 3.2 p5 of the standard says:

    There can be more than one definition of ... static data member of a class template ... in a program provided that each definition appears in a different translation unit,

    and

    If the definitions of D satisfy all these requirements, then the program shall behave as if there were a single definition of D.

    There are some requirements for this rule. In this question's case, since the variable is initialized by an integral constant 0, the requirements are satisfied.

提交回复
热议问题