As should be known, a line like #include <filename> causes the contents of the filename to be inserted instead of this line. Ie, connecting the file to any module X we get:
namespace whizbangStartData { float wSD_speed = static_cast<float>(0.2); const int wSD_UpX = 966, wSD_UpY = 303; ... } // 褋芯写械褉卸懈屑芯械 屑芯写褍谢褟 X
Separate modules (translation units) are compiled independently of each other. And when there are more than one modules that include the mentioned file, we get the names wSD_speed , wSD_UpX , etc. are present in each module. At the same time, internal constants implicitly use internal linking (i.e., they are not visible from another module, unless they are explicitly marked as extern ) and therefore the linker sees no problems with them when combining several modules. Another thing is variable. wSD_speed not a constant and its presence in the namespace makes it visible to other modules (i.e., implicit extern assumed for such variables). It turns out that in the whizbangStartData::wSD_speed process, when using whizbangStartData::wSD_speed in the code, it becomes unclear what kind of memory area is actually used and the linker displays the corresponding message.
There are several ways to eliminate the layout error:
Declare a variable in the header as extern float wSD_speed; , and define only in one of the modules.
Add static before float . This will make the variable invisible from outside the module, i.e. each module will have its own wSD_speed instance.
It is doubtful that the second option would be appropriate, but nevertheless, it solves the problem of layout.
namespace someNamespace { int someData = 123; }namespace someNamespace { int someData = 123; }for example - ampawd