Skip to content

Instantly share code, notes, and snippets.

@VeganPower
Last active March 30, 2022 13:49
Show Gist options
  • Save VeganPower/cd1f9963eb77ed40a23e02097ea24fd0 to your computer and use it in GitHub Desktop.
Save VeganPower/cd1f9963eb77ed40a23e02097ea24fd0 to your computer and use it in GitHub Desktop.
--- 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