Nonconstant parameter for a template class

I have a template class from an API that is instantiated with something like this.

BitField< length > object;

The problem is that length variable is only known at runtime.

error: 'length' cannot appear in a constant-expression -> this is the error message

Any suggestions ?
You can't do that. The compiler needs to generate templates at compile-time, as you can see. I would probably make that length parameter part of the constructor or something.
Assuming a bitfield is array of bits, then I would suggest boost::dynamic_bitset<> as a replacement.
Topic archived. No new replies allowed.