-
-
Save VeganPower/cd1f9963eb77ed40a23e02097ea24fd0 to your computer and use it in GitHub Desktop.
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
--- fileA.h --- | |
struct Singleton() | |
{ | |
static Singleton* Get() | |
{ | |
static Singleton the_instance; | |
return &the_instance; | |
} | |
map<string, int*> addresses; | |
}; | |
void foo(); | |
void bar(); | |
--- fileB.cpp --- | |
static int the_global = 42; | |
void foo() | |
{ | |
Singleton::Get()->addresses.insert(make_tuple(("nice"), &the_global)); | |
} | |
--- fileC.cpp --- | |
static int the_global = 69; | |
void bar() | |
{ | |
Singleton::Get()->addresses.insert(make_tuple(("nice"), &the_global)); | |
} | |
--- fileD.cpp --- | |
void piyo() | |
{ | |
foo(); | |
bar(); | |
assert(*Singleton::Get()->insert.find("nice") == 69); | |
} | |
void hoge() | |
{ | |
bar(); | |
foo(); | |
assert(*Singleton::Get()->insert.find("nice") == 42); // Not nice | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment