Static local variables in methods a bad practice?

前端 未结 5 1109
我在风中等你
我在风中等你 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:23

    Both local and non-local global variables are "bad" by the virtue of being global. But initialization and access for those two cases are different, so the answer which one to use depends on your needs regarding those requirements.

    As a side note, dynamic initialization of local variables with static storage duration may not be thread-safe, depending on your compiler. The good news, in C++0x it's guaranteed to be thread-safe.

提交回复
热议问题