What is the lifetime of a static variable in a C++ function?

后端 未结 5 1242
渐次进展
渐次进展 2020-11-22 03:32

If a variable is declared as static in a function\'s scope it is only initialized once and retains its value between function calls. What exactly is its lifetim

5条回答
  •  隐瞒了意图╮
    2020-11-22 04:06

    FWIW, Codegear C++Builder doesn't destruct in the expected order according to the standard.

    C:\> sample.exe 1 2
    Created in foo
    Created in if
    Destroyed in foo
    Destroyed in if
    

    ... which is another reason not to rely on the destruction order!

提交回复
热议问题