I expected the following code to work, but I received a compile error:
error C2975: 'n' : invalid template argument for 'foo', expected compile-time constant expression
#include <iostream>
using namespace std;
template<int N>
struct foo
{
foo() { cout << N << endl; }
};
int main()
{
foo< __LINE__ > f;
}
Why does this happen? I though __LINE__
would paste in the line number before template instantiation occurred?
If I wanted to do this should I just introduce a static const int
to hold the line number or is there a standard solution?