B
Bret Pehrson
I just stumbled across the following problem:
//.h
class Masses
{
static double mass1;
static double mass2;
static double mass3;
};
//.cpp
double Masses::mass1 = 123.0;
double Masses::mass2 = 456.0;
double Masses::mass3 = mass1/mass2;
// elsewhere (other translation unit)
double m = Masses::mass3; // m and Masses::mass3 == 0!
If I change mass3 initialization to a non-arithmetic literal, all works; leave
as arithmetic operation, and the value is set to 0.
So, my question is this: does the language mandate the initialization order of
such constants? I thought that it was based on the declaration order in the
class definition, but if that is the case, then mass3 should have a non-zero
value.
Is this a problem w/ my compiler (MSVC 2003), or a misunderstanding of the
language on my part?
FWIW: I also tried using static const in a namespace instead of as class
members, same behavior.
Thanks
//.h
class Masses
{
static double mass1;
static double mass2;
static double mass3;
};
//.cpp
double Masses::mass1 = 123.0;
double Masses::mass2 = 456.0;
double Masses::mass3 = mass1/mass2;
// elsewhere (other translation unit)
double m = Masses::mass3; // m and Masses::mass3 == 0!
If I change mass3 initialization to a non-arithmetic literal, all works; leave
as arithmetic operation, and the value is set to 0.
So, my question is this: does the language mandate the initialization order of
such constants? I thought that it was based on the declaration order in the
class definition, but if that is the case, then mass3 should have a non-zero
value.
Is this a problem w/ my compiler (MSVC 2003), or a misunderstanding of the
language on my part?
FWIW: I also tried using static const in a namespace instead of as class
members, same behavior.
Thanks