C++ Global variable declaration

You should 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;

Another way which is simpler is to use inline keyword. Put you variable in a header file as below:

inline bool bShouldRegister;

Leave a Comment