When exactly is constructor of static local object called?

Posted by Honza Bambas on Stack Overflow See other posts from Stack Overflow or by Honza Bambas
Published on 2010-06-17T15:21:13Z Indexed on 2010/06/17 15:23 UTC
Read the original article Hit count: 213

Filed under:
|
|
|

Say we have a code like this:

Some class {
  Some() { // the ctor code }
};

Some& globalFunction()
{
  static Some gSome;
  return gSome;
}

When exactly 'the ctor code' is executed? As for normal static variables before main() or at the moment we first call to 'globalFunction()'?

How is it on different platforms and different compilers (cl, gcc, ...) ?

Thanks

-hb-

© Stack Overflow or respective owner

Related posts about c++

Related posts about static