I'm porting some C++ code from gcc-3.3 to gcc-3.4 (and later gcc-4.0).
However I'm hitting an error I don't really know how to get around in a
clean way. The error tells me that a constant defined in terms of
another constant cannot be used as a template parameter, while if I
inline the first constant into the calculation of the second constant,
then everything works just fine. gcc-3.3 and earlier always compile it
without any errors.
If anyone can offer a way to make gcc happy, I'd appreciate it. I'd
like to avoid using defines if possible, and fix whatever the "real"
problem is. The full error and an example program which generates it
are given below.
Thanks,
Jim Bruce
=== COMPILE ERROR ====
% g++-3.4 const.cc -o const
const.cc: In function `int main()':
const.cc:13: error: `FrameRateInt_Bad' cannot appear in a
constant-expression
const.cc:13: error: template argument 1 is invalid
const.cc:13: error: invalid type in declaration before ';' token
==== EXAMPLE PROGRAM ====
// using a constant to define another constant is not ok...
static const double FrameRate = 60000.0 / 1001.0;
static const int FrameRateInt_Bad = (int)(FrameRate + 0.5);
// ... but inlining everything is ok
static const int FrameRateInt_Good = (int)((60000.0 / 1001.0) + 0.5);
template <const int N>
class Foo{
};
int main()
{
Foo<FrameRateInt_Good> f;
Foo<FrameRateInt_Bad> g;
return(0);
}