On local and global static variables in C++

前端 未结 7 1070
野的像风
野的像风 2020-11-29 05:55

C++ Primer says

Each local static variable is initialized before the first time execution passes through the object\'s definition. Local statics are

相关标签:
7条回答
  • 2020-11-29 06:31

    There real name is:

    static storage duration object.
    

    Global variables are also 'static storage duration object'. The major difference from global variables are:

    • They are not initialized until the first use
      Note: An exception during construction means they were not initialized and thus not used.
      So it will re-try the next time the function is entered.
    • Their visability is limited by their scope
      (ie they can not be seen outside the function)

    Apart from that they are just like other 'static storage duration objects'.

    Note: Like all 'static storage duration objects' they are destroyed in reverse order of creation.

    0 讨论(0)
提交回复
热议问题