I have a class that I’m using to store some static default variables for a visual experiment I’m creating.
They are not marked as const, because Im using a GUI to tweak them at runtime.
When I log them in the main class ( which calls the static function init on the Defaults class ) – they are valid. But in the constructor of the different class it returns zero.
The output looks like this
"Constants::init() called" // Constants::Heads::MIN_LIFETIME initialized to 1200
preSetup-Log Constants::Heads::MIN_LIFETIME 1200
PhysicsObject- Constants::Heads::MIN_LIFETIME 0 // Y you zero?
postSetup-Log Constants::Heads::MIN_LIFETIME 1200
I’m defining the constants like this:
namespace Constants {
namespace Forces {
static int MAX_LIFETIME;
static float GRAVITY_FORCE;
};
}
static void init() {
std::cout << "Constants::init()" << std::endl;
Constants::Forces::GRAVITY_FORCE = 40000.0f;
Constants::Forces::MAX_LIFETIME = 3000;
}
Then include
header.hin a file that uses the constants. The constants will be initialized automatically when the program starts.