C++ Global variable declaration

Solution 1:

You must use extern, otherwise you will have separated bShouldRegister variables in each translation unit with probably different values.

Put this in a header file (.h):

extern bool bShouldRegister;

Put this in one of implementation files (.cpp):

bool bShouldRegister;

Solution 2:

If you can use C++17, consider using an inline variable:

// in a header file
inline bool bShouldRegister = true;

See How do inline variables work? for more information.