const static integral members

Hello,

Excuse me if this is stupid. I've been having a problem concerning the initialization of const static integral members with floating point calculations.
I'll let his sample program do the explaining:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
class Foo {
public :
	Foo() {}

	const static int samplerate = 44100;
	const static unsigned short tempo = 120;
	const static int numSamples = (int)(((double)4.0/((double)tempo/(double)60.0)) * (double)samplerate);//error - expected constant expression
	//const static int numSamples = (4/(tempo/60)) * samplerate;//works, but is inaccurate


};

int main(int argc, char* argv[]) {
	Foo foo;

	return 0;
}


I know you can't initialize const static non-integral types on the same line on which they're declared, but I don't see why even an implicit cast to an integral type should be disallowed. I make my calculations using doubles, so I'm surprised that even though it should degenerate into an integer - it's still a problem for the compiler.
Last edited on
Topic archived. No new replies allowed.