Global vector emptying itself between calls?

前端 未结 2 1866
鱼传尺愫
鱼传尺愫 2021-01-18 11:44

I have a vector in a header, like so:

extern std::vector g_vector;

In the associated cpp file I have this:

std::         


        
2条回答
  •  我在风中等你
    2021-01-18 12:17

    Order of initialization of global values is not defined.

    Read here about the static initialization fiasco.

    When you declare Bar in a function - the g_vector will be initialized before, because its promised to be initialized before the program runs. If Bar is a global variable - then you have a problem.

提交回复
热议问题