Don’t understand static boolean behavior

static in this context means “local” (to the translation unit). There will be multiple copies of read_mess in your program, one per translation unit which is not the same thing as a header file. (In your case you can most likely approximate “translation unit” as .cpp or .c or .cc file).

Probably what you meant to do was to declare an extern variable, or static class member and define it in just one translation unit.

In practice using extern means in your header file you want to write:

extern bool read_mess;

But in one and only one other place that isn’t a header:

bool read_mess = false;

Leave a Comment