Const variables can be optimized out by the compiler, if you don't use its address it might not even allocate any storage for it, just inlines the constant value into the code directly. If you don't use const then it can't do this optimization and in your program there will be 2 object files that export the same symbol so it can cause a link time collision. - You can avoid this collision by changing the C++ default public storage specifier by either adding the "static" specifier to at least one of the variables or putting at least one of the variables to an anonymous namespace{} that does the same as the static keyword.
Note that this might be the side effect of a C++ feature that wasn't available for some time, that is you can put a const integer definition into a header file now instead of using a #define. This is true only for integer types. Before this feature everyone was using enums to put integer constants to header files and into class definitions.
EDIT: You might wonder that some other cpp files might want to use this "const int X" with extern, and how would they do it if it isn't exported from its object file at all. You can force exporting it and allocate storage with "extern":
DEFINITION:
extern const int XX = 0;
DECLARATION:
extern const int XX;
EDIT:
Constant Values[
^]
Somewhere near the beginning of the article:
Quote:
In C, constant values default to external linkage, so they can appear only in source files. In C++, constant values default to internal linkage, which allows them to appear in header files.