我正在制作一个游戏,有一个有趣的问题。我有一些游戏范围的常量值,希望在一个文件中实现。目前我有类似这样的东西:
常量.cpp
extern const int BEGINNING_HEALTH = 10;
extern const int BEGINNING_MANA = 5;
常数.hpp
extern const int BEGINNING_HEALTH;
extern const int BEGINNING_MANA;
And then files just #include "常数.hpp" This was working great, until I needed to use one of the constants as a template parameter, because externally-linked constants are not valid template parameters. So my question is, what is the best way to implement these constants? I am afraid that simply putting the constants in a header file will cause them to be defined in each translation unit. And I don t want to use macros.
谢谢 (xiè xiè)