C++ global extern constant defined at runtime available across multiple source files
问题 I have an integer constant that is to be defined at runtime. This constant needs to be available globally and across multiple source files. I currently have the following simplified situation: ClassA.h declares extern const int someConstant; ClassA.cpp uses someConstant at some point. Constants.h declares extern const int someConstant; main.cpp includes ClassA.h and Constants.h , declares const int someConstant , and at some point during main() tries to initialize someConstant to the real