static variable vs. member

前端 未结 3 1193
轻奢々
轻奢々 2021-02-07 17:25

If you have data for a class that will be modified and needs to be retained throughout the program, but is only used in one member function, is it preferred to make that variabl

3条回答
  •  一向
    一向 (楼主)
    2021-02-07 17:58

    I would argue that in most cases, you should never use a local static variable, and instead use a static member variable. Then the question degenerates to if that variable should be shared among the class instances or not.

提交回复
热议问题