Maybe it is base knowledge, I am apologize.
I have a header file CTemp.h, with namespace CTemp:
namespace CTemp { bool bFlag; }; #ifndef _CTEMP #define _CTEMP bool CTemp::bFlag = true; #endif and if I include CTemp.h to my cpp file and try to use CTemp::bFlag
bool bb = CTemp::bFlag; the compiler throw error "redefinition"
I surely know, that I should to put initialization to a .cpp file, but I find some way, to solve it only with .h file. Because I don't want to add the .cpp file to my project. I thought, I could solve it with preprocessor directives #ifdef....
Thanks for advice.
extern bool bFlagin your H file (declaration), andbool bFlag = true;in the CPP (definition). However - using global variables is usually not a good idea (to say the least).bool bFlag;andbool CTemp::bFlag = true;are definitions.