Initialization of object static members

前端 未结 7 1050
余生分开走
余生分开走 2021-01-24 21:51

Static members confuse me sometimes. I understand how to initialize a simple built in type such as int with something along the lines of int myClass::statVar

7条回答
  •  时光说笑
    2021-01-24 22:33

    Put it in a private field, expose a static accessor. In the accessor, if the member is not yet initialized, initialize it.

提交回复
热议问题