Static local variables in methods a bad practice?

前端 未结 5 1112
我在风中等你
我在风中等你 2021-01-04 22:44

there is something that\'s bugging me.

In a non-threaded program, is it better to have local static variables(inside methods) or static class members?

In thi

5条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-04 23:35

    If it's a public class, a static class member requires editing the header file. This is not always desirable.

    Another option is a file-scoped variable, in an anonymous namespace. This is sufficient if you need access only in one method, and if you need it in multiple.

提交回复
热议问题