I
Imre
Is there a Visual C++ newsgroup? I guess this question should go there,
but I couldn't find it.
Please take a look at the following little program:
template <int Line>
struct Test
{
enum { value = Line };
};
int main(int argc, char *argv[])
{
int i = Test<__LINE__>::value;
return 0;
}
Visual C++ 7.1 refuses to compile it, giving this error message for the
line in main where Test<__LINE__> is referenced:
error C2975: 'Line' : invalid template argument for 'Test',
compile-time evaluatable constant expression expected
I can't really understand what the problem is. By the time the compiler
ever sees this code, __LINE__ should already have been replaced with an
integer constant, which is definitely a compile-time evaluatable
constant expression. And in fact, if I manually replace __LINE__ with,
say, 42, it compiles fine. What's even funnier is that if I tell the
compiler to generate a preprocessed file, it compiles well.
Does anyone know what the problem is? And more importantly, what can I
do to avoid it?
Imre
but I couldn't find it.
Please take a look at the following little program:
template <int Line>
struct Test
{
enum { value = Line };
};
int main(int argc, char *argv[])
{
int i = Test<__LINE__>::value;
return 0;
}
Visual C++ 7.1 refuses to compile it, giving this error message for the
line in main where Test<__LINE__> is referenced:
error C2975: 'Line' : invalid template argument for 'Test',
compile-time evaluatable constant expression expected
I can't really understand what the problem is. By the time the compiler
ever sees this code, __LINE__ should already have been replaced with an
integer constant, which is definitely a compile-time evaluatable
constant expression. And in fact, if I manually replace __LINE__ with,
say, 42, it compiles fine. What's even funnier is that if I tell the
compiler to generate a preprocessed file, it compiles well.
Does anyone know what the problem is? And more importantly, what can I
do to avoid it?
Imre