static variable vs. member

前端 未结 3 1199
轻奢々
轻奢々 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:48

    The question isn't "will the data be used throughout the program", but rather "if you make two objects of this class, do you want them to share this data?" If yes, make it static. If no, don't.

提交回复
热议问题