Created
October 15, 2010 09:46
-
-
Save engie/627926 to your computer and use it in GitHub Desktop.
Reminding myself of the order of static initialisation.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
class C | |
{ | |
public: | |
C() | |
{ | |
printf("Created C\n"); | |
} | |
}; | |
C& getC() | |
{ | |
printf("In function\n"); | |
static C c; | |
printf("Below static initialiser.\n"); | |
return c; | |
} | |
int main(int argc, char **argv) | |
{ | |
printf("Starting\n"); | |
C& c = getC(); | |
printf("Done\n"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Outputs:
Starting
In function
Created C
Below static initialiser.
Done